import { assertClerkSingletonExists } from "./utils.js";
import React from "react";
import { ClerkInstanceContext, ClientContext, OrganizationProvider, SessionContext, UserContext, __experimental_CheckoutProvider } from "@clerk/shared/react";
import { jsx } from "@emotion/react/jsx-runtime";

//#region src/contexts/CoreClerkContextWrapper.tsx
function CoreClerkContextWrapper(props) {
	const clerk = props.clerk;
	assertClerkSingletonExists(clerk);
	const [state, setState] = React.useState({
		client: clerk.client,
		session: clerk.session,
		user: clerk.user,
		organization: clerk.organization
	});
	React.useEffect(() => {
		return clerk.addListener((e) => setState({ ...e }));
	}, []);
	const { client, session, user, organization } = state;
	const clerkCtx = React.useMemo(() => ({ value: clerk }), []);
	const clientCtx = React.useMemo(() => ({ value: client }), [client]);
	const sessionCtx = React.useMemo(() => ({ value: session }), [session]);
	const userCtx = React.useMemo(() => ({ value: user }), [user]);
	const organizationCtx = React.useMemo(() => ({ value: { organization } }), [organization]);
	return /* @__PURE__ */ jsx(ClerkInstanceContext.Provider, {
		value: clerkCtx,
		children: /* @__PURE__ */ jsx(ClientContext.Provider, {
			value: clientCtx,
			children: /* @__PURE__ */ jsx(SessionContext.Provider, {
				value: sessionCtx,
				children: /* @__PURE__ */ jsx(OrganizationProvider, {
					...organizationCtx.value,
					children: /* @__PURE__ */ jsx(UserContext.Provider, {
						value: userCtx,
						children: /* @__PURE__ */ jsx(__experimental_CheckoutProvider, {
							value: void 0,
							children: props.children
						})
					})
				})
			})
		})
	});
}

//#endregion
export { CoreClerkContextWrapper };
//# sourceMappingURL=CoreClerkContextWrapper.js.map