"use client";
import { useEnvironmentContext } from "../../providers/environment/use-environment-context.js";
import { useLocaleContext } from "../../providers/locale/use-locale-context.js";
import * as collapsible from "@zag-js/collapsible";
import { useId, useRef } from "react";
import { normalizeProps, useMachine } from "@zag-js/react";
//#region src/components/collapsible/use-collapsible.ts
var useCollapsible = (props = {}) => {
	const { lazyMount, unmountOnExit, ...collapsibleProps } = props;
	const id = useId();
	const wasVisible = useRef(false);
	const { dir } = useLocaleContext();
	const { getRootNode } = useEnvironmentContext();
	const machineProps = {
		id,
		dir,
		getRootNode,
		...collapsibleProps
	};
	const service = useMachine(collapsible.machine, machineProps);
	const api = collapsible.connect(service, normalizeProps);
	if (api.visible) wasVisible.current = true;
	const isUnmounted = !api.visible && !wasVisible.current && lazyMount || unmountOnExit && !api.visible && wasVisible.current;
	return {
		...api,
		isUnmounted
	};
};
//#endregion
export { useCollapsible };
