require("./chunk-9hOWP6kD.cjs");
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");
//#region ../react/src/shell/ScreenHeaderContext.tsx
/**
* Split into separate read/write contexts so that components calling
* useScreenHeaderActions (writers) don't re-render when the actions
* state changes — only the ScreenHeader (reader) re-renders.
*/
const ScreenHeaderWriteContext = (0, react.createContext)(null);
const ScreenHeaderReadContext = (0, react.createContext)(null);
const ScreenHeaderBreadcrumbsWriteContext = (0, react.createContext)(null);
const ScreenHeaderBreadcrumbsReadContext = (0, react.createContext)(null);
function ScreenHeaderProvider({ children }) {
	const [actions, setActions] = (0, react.useState)(null);
	const [breadcrumbs, setBreadcrumbs] = (0, react.useState)(null);
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ScreenHeaderWriteContext.Provider, {
		value: setActions,
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ScreenHeaderReadContext.Provider, {
			value: actions,
			children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ScreenHeaderBreadcrumbsWriteContext.Provider, {
				value: setBreadcrumbs,
				children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ScreenHeaderBreadcrumbsReadContext.Provider, {
					value: breadcrumbs,
					children
				})
			})
		})
	});
}
/**
* Sets actions to display in the ScreenHeader.
* Returns `true` if inside a ScreenHeaderProvider (i.e., in the portal shell),
* `false` otherwise. Pages can use this boolean to conditionally skip
* rendering their own PageHeader.
*
* Cleans up actions on unmount so navigating away doesn't leave stale actions.
*/
function useScreenHeaderActions(actions) {
	const setActions = (0, react.useContext)(ScreenHeaderWriteContext);
	const setActionsRef = (0, react.useRef)(setActions);
	setActionsRef.current = setActions;
	(0, react.useEffect)(() => {
		if (!setActions) return;
		setActions(actions);
	}, [actions, setActions]);
	(0, react.useEffect)(() => {
		return () => setActionsRef.current?.(null);
	}, []);
	return setActions !== null;
}
/**
* Sets breadcrumbs to display in the ScreenHeader (in place of the plain title).
* Returns `true` if inside a ScreenHeaderProvider (i.e., in the portal shell),
* `false` otherwise.
*
* Cleans up breadcrumbs on unmount so navigating away doesn't leave stale breadcrumbs.
*/
function useScreenHeaderBreadcrumbs(breadcrumbs) {
	const setBreadcrumbs = (0, react.useContext)(ScreenHeaderBreadcrumbsWriteContext);
	const setBreadcrumbsRef = (0, react.useRef)(setBreadcrumbs);
	setBreadcrumbsRef.current = setBreadcrumbs;
	(0, react.useEffect)(() => {
		if (!setBreadcrumbs) return;
		setBreadcrumbs(breadcrumbs);
	}, [breadcrumbs, setBreadcrumbs]);
	(0, react.useEffect)(() => {
		return () => setBreadcrumbsRef.current?.(null);
	}, []);
	return setBreadcrumbs !== null;
}
/**
* Reads the current screen header actions and breadcrumbs. Used internally by ScreenHeader.
*/
function useScreenHeaderContext() {
	const actions = (0, react.useContext)(ScreenHeaderReadContext);
	const breadcrumbs = (0, react.useContext)(ScreenHeaderBreadcrumbsReadContext);
	return {
		actions: actions ?? null,
		breadcrumbs: breadcrumbs ?? null
	};
}
//#endregion
Object.defineProperty(exports, "ScreenHeaderProvider", {
	enumerable: true,
	get: function() {
		return ScreenHeaderProvider;
	}
});
Object.defineProperty(exports, "useScreenHeaderActions", {
	enumerable: true,
	get: function() {
		return useScreenHeaderActions;
	}
});
Object.defineProperty(exports, "useScreenHeaderBreadcrumbs", {
	enumerable: true,
	get: function() {
		return useScreenHeaderBreadcrumbs;
	}
});
Object.defineProperty(exports, "useScreenHeaderContext", {
	enumerable: true,
	get: function() {
		return useScreenHeaderContext;
	}
});

//# sourceMappingURL=ScreenHeaderContext-JDIUM84f.cjs.map