import { computed, toRef, isRef } from 'vue'; import { u as useNuxtApp } from './server.mjs'; const useStateKeyPrefix = "$s"; function useState(...args) { const autoKey = typeof args[args.length - 1] === "string" ? args.pop() : void 0; if (typeof args[0] !== "string") { args.unshift(autoKey); } const [_key, init] = args; if (!_key || typeof _key !== "string") { throw new TypeError("[nuxt] [useState] key must be a string: " + _key); } if (init !== void 0 && typeof init !== "function") { throw new Error("[nuxt] [useState] init must be a function: " + init); } const key = useStateKeyPrefix + _key; const nuxtApp = useNuxtApp(); const state = toRef(nuxtApp.payload.state, key); if (init) { nuxtApp._state[key] ??= { _default: init }; } if (state.value === void 0 && init) { const initialValue = init(); if (isRef(initialValue)) { nuxtApp.payload.state[key] = initialValue; return initialValue; } state.value = initialValue; } return state; } function useLoading() { const count = useState("app:loading", () => 0); const loading = computed(() => count.value > 0); function begin() { count.value++; } function end() { count.value = Math.max(0, count.value - 1); } return { count, loading, begin, end }; } export { useState as a, useLoading as u }; //# sourceMappingURL=useLoading-D4zrSa2m.mjs.map