import { runIfFn } from "../utils/function.js";
import { filterUndefined } from "../utils/object.js";
import { PopoverProvider } from "./context.js";
import PopoverContent from "./popoverContent.js";
import PopoverTrigger from "./popoverTrigger.js";
import usePopover from "./usePopover.js";
import { jsx } from "react/jsx-runtime";
import { FloatingNode, FloatingTree, useFloatingNodeId, useFloatingParentNodeId } from "@floating-ui/react";

//#region src/popover/popover.tsx
/**
* Uses 'usePopover' hook to expose relevant data to its children parts.
* By default, renders provided content only when popover is opened (lazy).
*/
function PopoverInner(props) {
	const nodeId = useFloatingNodeId();
	const { children, isLazy = true, ...rest } = props;
	const popoverProps = usePopover({
		...rest,
		nodeId
	});
	const { close, isOpen, open } = popoverProps;
	return /* @__PURE__ */ jsx(FloatingNode, {
		id: nodeId,
		children: /* @__PURE__ */ jsx(PopoverProvider, {
			value: filterUndefined({
				isLazy,
				...popoverProps
			}),
			children: runIfFn(children, {
				close,
				isOpen,
				open
			})
		})
	});
}
function Popover(props) {
	if (useFloatingParentNodeId() === null) return /* @__PURE__ */ jsx(FloatingTree, { children: /* @__PURE__ */ jsx(PopoverInner, { ...props }) });
	return /* @__PURE__ */ jsx(PopoverInner, { ...props });
}
Popover.Content = PopoverContent;
Popover.Trigger = PopoverTrigger;
Popover.displayName = "Popover";

//#endregion
export { Popover as default };
globalThis.__vuiVersion__ = "4.0.3"
//# sourceMappingURL=popover.js.map