'use client';

import { getAuthAPI } from "../../libs/auth.mjs";
import { useQueryClient } from "../reactQuery.mjs";
import { useConfiguration } from "@intlayer/editor-react";
import { useQuery } from "@tanstack/react-query";
import configuration from "@intlayer/config/built";

//#region src/hooks/useAuth/useSession.ts
function useSession(sessionProp, intlayerConfiguration) {
	const configuration$1 = useConfiguration();
	const config = intlayerConfiguration ?? configuration$1 ?? configuration;
	const queryClient = useQueryClient();
	const { data, isFetched, refetch } = useQuery({
		queryKey: ["session"],
		queryFn: async () => {
			return (await getAuthAPI(config).getSession()).data;
		},
		staleTime: 0,
		gcTime: 300 * 1e3,
		refetchOnMount: "always",
		refetchOnWindowFocus: false,
		refetchOnReconnect: false,
		enabled: !sessionProp
	});
	const session = data ?? (isFetched ? null : void 0);
	const setSession = (nextSession) => {
		queryClient.setQueryData(["session"], nextSession);
	};
	const fetchSession = async () => {
		return (await refetch()).data;
	};
	return {
		session,
		fetchSession,
		revalidateSession: fetchSession,
		setSession
	};
}

//#endregion
export { useSession };
//# sourceMappingURL=useSession.mjs.map