/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-af8d194 | Cube Dev Team */
import { tasty } from "../../../tasty/tasty.js";
import { mergeProps as mergeProps$1 } from "../../../utils/react/mergeProps.js";
import { _Overlay } from "./Overlay.js";
import { forwardRef, useEffect } from "react";
import { jsx } from "react/jsx-runtime";
import { useModal, useOverlay } from "react-aria";

//#region src/components/overlays/Modal/Popover.tsx
const PopoverElement = tasty({
	role: "presentation",
	styles: {
		display: {
			"": "none",
			"entering | entered": "initial",
			exiting: "initial",
			exited: "none"
		},
		pointerEvents: "auto",
		position: "absolute",
		transition: "opacity .120s linear, visibility 0ms linear, transform .120s ease-in-out",
		transform: {
			"": "scale(1, .9)",
			open: "initial"
		},
		opacity: {
			"": 0,
			open: ".9999"
		},
		transformOrigin: {
			"": "top center",
			"[data-placement=\"top\"]": "bottom center"
		}
	}
});
function Popover(props, ref) {
	let { qa, style, styles, children, placement, arrowProps, onClose, shouldCloseOnBlur, isKeyboardDismissDisabled, isNonModal, isDismissable = true, updatePosition, shouldCloseOnInteractOutside, ...otherProps } = props;
	return /* @__PURE__ */ jsx(_Overlay, {
		...otherProps,
		children: /* @__PURE__ */ jsx(PopoverWrapper, {
			ref,
			qa,
			style,
			styles,
			placement,
			arrowProps,
			shouldCloseOnBlur,
			isKeyboardDismissDisabled,
			isNonModal,
			isDismissable,
			updatePosition,
			shouldCloseOnInteractOutside,
			onClose,
			children
		})
	});
}
const PopoverWrapper = forwardRef(function PopoverWrapper(props, ref) {
	let { qa, children, placement = "bottom", arrowProps, isOpen, style, styles, shouldCloseOnBlur, isKeyboardDismissDisabled, isNonModal, isDismissable, updatePosition, transitionState, shouldCloseOnInteractOutside, ...otherProps } = props;
	let { overlayProps } = useOverlay({
		...props,
		isDismissable: isDismissable && isOpen
	}, ref);
	let { modalProps } = useModal({ isDisabled: isNonModal });
	useEffect(() => {
		if (transitionState === "entered") updatePosition?.();
	}, [updatePosition, transitionState]);
	return /* @__PURE__ */ jsx(PopoverElement, {
		qa: qa || "Popover",
		...mergeProps$1(otherProps, overlayProps, modalProps),
		ref,
		styles,
		mods: {
			open: isOpen,
			entering: transitionState === "entering",
			exiting: transitionState === "exiting",
			exited: transitionState === "exited",
			entered: transitionState === "entered"
		},
		"data-placement": placement,
		style,
		children
	});
});
const _Popover = forwardRef(Popover);
_Popover.displayName = "Popover";

//#endregion
export { _Popover };
//# sourceMappingURL=Popover.js.map