/**
 * Copyright IBM Corp. 2020, 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_usePresenceContext = require("./usePresenceContext.js");
let react = require("react");
react = require_runtime.__toESM(react);
//#region src/components/Tearsheet/TearsheetPresence.tsx
/**
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const TearsheetPresence = ({ open, _presenceId: presenceId, _autoEnablePresence: autoEnablePresence = true, children }) => {
	const [isPresent, context] = require_usePresenceContext.usePresenceContext(open, presenceId);
	const contextValue = (0, react.useMemo)(() => ({
		autoEnablePresence,
		...context
	}), [autoEnablePresence, context]);
	if (!isPresent) return null;
	return /* @__PURE__ */ react.default.createElement(TearsheetPresenceContext.Provider, { value: contextValue }, children);
};
const TearsheetPresenceContext = (0, react.createContext)(void 0);
/**
* Handles occurrences where only a single modal must consume a context.
*/
const useExclusiveTearsheetPresenceContext = (id) => {
	const ctx = (0, react.useContext)(TearsheetPresenceContext);
	return ctx?.isPresenceExclusive(id) ? ctx : void 0;
};
/**
* Higher-order function that wraps a component with ModalPresence
*/
const withTearsheetPresence = (Component) => {
	const WithModalPresence = (props) => {
		const { open, ...componentProps } = props;
		return /* @__PURE__ */ react.default.createElement(TearsheetPresence, { open }, /* @__PURE__ */ react.default.createElement(Component, componentProps));
	};
	WithModalPresence.displayName = `withModalPresence(${Component.displayName || Component.name || "Component"})`;
	return WithModalPresence;
};
//#endregion
exports.TearsheetPresence = TearsheetPresence;
exports.TearsheetPresenceContext = TearsheetPresenceContext;
exports.useExclusiveTearsheetPresenceContext = useExclusiveTearsheetPresenceContext;
exports.withTearsheetPresence = withTearsheetPresence;
