"use client";
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
const require_use_event = require("../../utils/use-event.cjs");
let react = require("react");
let _zag_js_react = require("@zag-js/react");
let _zag_js_presence = require("@zag-js/presence");
_zag_js_presence = require_runtime.__toESM(_zag_js_presence, 1);
//#region src/components/presence/use-presence.ts
var usePresence = (props = {}) => {
	const { lazyMount, unmountOnExit, present, skipAnimationOnMount = false, ...rest } = props;
	const wasEverPresent = (0, react.useRef)(false);
	const machineProps = {
		...rest,
		present,
		onExitComplete: require_use_event.useEvent(props.onExitComplete)
	};
	const service = (0, _zag_js_react.useMachine)(_zag_js_presence.machine, machineProps);
	const api = _zag_js_presence.connect(service, _zag_js_react.normalizeProps);
	if (api.present) wasEverPresent.current = true;
	const unmounted = !api.present && !wasEverPresent.current && lazyMount || unmountOnExit && !api.present && wasEverPresent.current;
	const getPresenceProps = () => ({
		"data-state": api.skip && skipAnimationOnMount ? void 0 : present ? "open" : "closed",
		hidden: !api.present
	});
	return {
		ref: api.setNode,
		getPresenceProps,
		present: api.present,
		unmounted
	};
};
//#endregion
exports.usePresence = usePresence;
