require("./chunk-9hOWP6kD.cjs");
let react = require("react");
let _tanstack_react_query = require("@tanstack/react-query");
//#region ../core/src/store-api-context.ts
const StoreApiContext = (0, react.createContext)(null);
const StoreApiProvider = StoreApiContext.Provider;
function useStoreApi() {
	const api = (0, react.use)(StoreApiContext);
	if (!api) throw new Error("useStoreApi must be used within a StoreApiProvider");
	return api;
}
/**
* Non-throwing variant for contexts where a StoreApiProvider may be absent
* (e.g. the screen-builder widget palette/drag-preview, which mounts only the
* widget preview providers). Returns null instead of throwing so callers can
* fall back to default copy.
*/
function useOptionalStoreApi() {
	return (0, react.use)(StoreApiContext);
}
//#endregion
//#region ../react/src/hooks/use-optional-store.ts
/** Shared cache key + staleTime for the tenant store query. */
const STORE_QUERY_KEY = ["portalTenant", "store"];
const STORE_STALE_TIME = 300 * 1e3;
/**
* Builds the tenant-store query fn. Shared by `useStore()` (sdk) and
* `useOptionalStore()` so the fetch + response mapping lives in one place.
*/
function fetchStoreQuery(api) {
	return async () => {
		return (await api.fetchStore()).store;
	};
}
/**
* Tenant-store query that tolerates a missing `StoreApiProvider` (e.g. the
* widget palette / drag-preview, which mounts widgets without one). Returns a
* disabled query instead of throwing, and shares the cache key + staleTime with
* `useStore()` so both resolve from the same cache entry.
*/
function useOptionalStore() {
	const api = useOptionalStoreApi();
	return (0, _tanstack_react_query.useQuery)({
		queryKey: STORE_QUERY_KEY,
		queryFn: fetchStoreQuery(api),
		enabled: api !== null,
		staleTime: STORE_STALE_TIME
	});
}
//#endregion
Object.defineProperty(exports, "STORE_QUERY_KEY", {
	enumerable: true,
	get: function() {
		return STORE_QUERY_KEY;
	}
});
Object.defineProperty(exports, "STORE_STALE_TIME", {
	enumerable: true,
	get: function() {
		return STORE_STALE_TIME;
	}
});
Object.defineProperty(exports, "StoreApiProvider", {
	enumerable: true,
	get: function() {
		return StoreApiProvider;
	}
});
Object.defineProperty(exports, "fetchStoreQuery", {
	enumerable: true,
	get: function() {
		return fetchStoreQuery;
	}
});
Object.defineProperty(exports, "useOptionalStore", {
	enumerable: true,
	get: function() {
		return useOptionalStore;
	}
});
Object.defineProperty(exports, "useStoreApi", {
	enumerable: true,
	get: function() {
		return useStoreApi;
	}
});

//# sourceMappingURL=use-optional-store-DT54mwJS.cjs.map