import { c as ZIndex, n as AnalyticsId } from "./constants2.js";
import { n as getAriaLabelAttributes } from "./accessibility.js";
import { _ as autoUpdate, a as useDismiss, d as arrow, f as flip, h as shift, i as useClick, l as useInteractions, m as offset, o as useFloating, p as hide, r as FloatingFocusManager, t as FloatingArrow, u as useMergeRefs } from "./floating-ui.react.js";
import classNames from "classnames";
import { useRef } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import styles from "./components/PopOver/styles.module.scss";
let PopOverVariant = /* @__PURE__ */ function(PopOverVariant$1) {
	PopOverVariant$1["positionautomatic"] = "positionautomatic";
	PopOverVariant$1["positionbelow"] = "positionbelow";
	PopOverVariant$1["positionabove"] = "positionabove";
	return PopOverVariant$1;
}({});
var PopOver = (props) => {
	const { ariaLabel, ariaLabelledById, id, children, controllerRef, show = false, className = "", variant = PopOverVariant.positionautomatic, role = "dialog", testId, zIndex = ZIndex.PopOver, placement, ref } = props;
	const ariaLabelAttributes = getAriaLabelAttributes({
		label: ariaLabel,
		id: ariaLabelledById
	});
	const placementProp = placement ?? (variant === PopOverVariant.positionabove ? "top" : "bottom");
	const arrowRef = useRef(null);
	const { refs, floatingStyles, context, middlewareData } = useFloating({
		middleware: [
			offset(10),
			flip(),
			shift({ padding: 8 }),
			hide(),
			arrow({ element: arrowRef })
		],
		placement: placementProp,
		whileElementsMounted: autoUpdate,
		elements: { reference: controllerRef.current }
	});
	const { getFloatingProps } = useInteractions([useClick(context), useDismiss(context)]);
	const isVisible = show && !middlewareData.hide?.referenceHidden;
	return /* @__PURE__ */ jsx(FloatingFocusManager, {
		context,
		modal: false,
		children: /* @__PURE__ */ jsxs("div", {
			id,
			ref: useMergeRefs([refs.setFloating, ref]),
			style: {
				...floatingStyles,
				visibility: isVisible ? "visible" : "hidden",
				zIndex
			},
			className: classNames(styles.popover, className),
			...getFloatingProps(),
			role,
			"data-testid": testId,
			"data-analyticsid": AnalyticsId.PopOver,
			...ariaLabelAttributes,
			children: [children, /* @__PURE__ */ jsx(FloatingArrow, {
				ref: arrowRef,
				className: styles["popover__arrow"],
				context,
				fill: "var(--core-color-white)",
				stroke: "var(--color-base-border-onlight)",
				strokeWidth: 1
			})]
		})
	});
};
PopOver.displayName = "PopOver";
var PopOver_default$1 = PopOver;
export { PopOverVariant as n, PopOver_default$1 as t };

//# sourceMappingURL=PopOver.js.map