import { createContext, use, useCallback, useLayoutEffect, useMemo, useState } from "react";
import { jsx } from "react/jsx-runtime";
import { createPortal } from "react-dom";
//#region ../react/src/shell/ScreenHeaderContext.tsx
const SlotContext = createContext(null);
function ScreenHeaderProvider({ children }) {
	const [breadcrumbsEl, setBreadcrumbsEl] = useState(null);
	const [actionsEl, setActionsEl] = useState(null);
	const [breadcrumbCount, setBreadcrumbCount] = useState(0);
	const incrementBreadcrumbs = useCallback(() => setBreadcrumbCount((c) => c + 1), []);
	const decrementBreadcrumbs = useCallback(() => setBreadcrumbCount((c) => c - 1), []);
	const value = useMemo(() => ({
		breadcrumbsEl,
		actionsEl,
		breadcrumbCount,
		incrementBreadcrumbs,
		decrementBreadcrumbs,
		setBreadcrumbsEl,
		setActionsEl
	}), [
		breadcrumbsEl,
		actionsEl,
		breadcrumbCount,
		incrementBreadcrumbs,
		decrementBreadcrumbs,
		setBreadcrumbsEl,
		setActionsEl
	]);
	return /* @__PURE__ */ jsx(SlotContext.Provider, {
		value,
		children
	});
}
function ScreenHeaderBreadcrumbs({ children }) {
	const ctx = use(SlotContext);
	const increment = ctx?.incrementBreadcrumbs;
	const decrement = ctx?.decrementBreadcrumbs;
	useLayoutEffect(() => {
		increment?.();
		return () => decrement?.();
	}, [increment, decrement]);
	if (!ctx?.breadcrumbsEl) return null;
	return createPortal(children, ctx.breadcrumbsEl);
}
function ScreenHeaderActions({ children }) {
	const ctx = use(SlotContext);
	if (!ctx?.actionsEl) return null;
	return createPortal(children, ctx.actionsEl);
}
function useScreenHeaderSlotRefs() {
	const ctx = use(SlotContext);
	if (!ctx) throw new Error("useScreenHeaderSlotRefs must be used within a ScreenHeaderProvider");
	return {
		breadcrumbsRef: ctx.setBreadcrumbsEl,
		actionsRef: ctx.setActionsEl,
		hasBreadcrumbs: ctx.breadcrumbCount > 0
	};
}
//#endregion
export { useScreenHeaderSlotRefs as i, ScreenHeaderBreadcrumbs as n, ScreenHeaderProvider as r, ScreenHeaderActions as t };

//# sourceMappingURL=ScreenHeaderContext-BA8__sLA.mjs.map