import { useRouter } from "../../router/RouteContext.js";
import { createContext, useContext } from "react";
import { getTaskEndpoint } from "@clerk/shared/internal/clerk-js/sessionTasks";

//#region src/contexts/components/SessionTasks.ts
const SessionTasksContext = createContext(null);
const useSessionTasksContext = () => {
	const context = useContext(SessionTasksContext);
	const { navigate, basePath, startPath } = useRouter();
	if (context === null) throw new Error("Clerk: useSessionTasksContext called outside of the mounted SessionTasks component.");
	const navigateOnSetActive = async ({ session, redirectUrlComplete, decorateUrl }) => {
		const currentTask = session.currentTask;
		if (!currentTask) {
			const decoratedUrl = decorateUrl(redirectUrlComplete);
			if (decoratedUrl !== redirectUrlComplete && /^https?:\/\//.test(decoratedUrl)) {
				window.location.href = decoratedUrl;
				return;
			}
			return navigate(redirectUrlComplete);
		}
		const taskEndpoint = getTaskEndpoint(currentTask);
		return navigate(`/${basePath + startPath + taskEndpoint}`);
	};
	return {
		...context,
		navigateOnSetActive
	};
};
const TaskChooseOrganizationContext = createContext(null);
const useTaskChooseOrganizationContext = () => {
	const context = useContext(TaskChooseOrganizationContext);
	if (context === null) throw new Error("Clerk: useTaskChooseOrganizationContext called outside of the mounted TaskChooseOrganization component.");
	return context;
};
const TaskResetPasswordContext = createContext(null);
const useTaskResetPasswordContext = () => {
	const context = useContext(TaskResetPasswordContext);
	if (context === null) throw new Error("Clerk: useTaskResetPasswordContext called outside of the mounted TaskResetPassword component.");
	return context;
};

//#endregion
export { SessionTasksContext, TaskChooseOrganizationContext, TaskResetPasswordContext, useSessionTasksContext, useTaskChooseOrganizationContext, useTaskResetPasswordContext };
//# sourceMappingURL=SessionTasks.js.map