import { t as e } from "./floating-arrow-BE-z4QkE.js";
import { cloneElement as t, createContext as n, useCallback as r, useContext as i, useEffect as a, useRef as o, useState as s } from "react";
import { cn as c } from "@ryuzaki13/react-foundation-lib/utils";
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
import { FloatingPortal as f, arrow as p, autoUpdate as m, flip as h, offset as g, shift as _, useDismiss as v, useFloating as y, useHover as b, useInteractions as x, useRole as S } from "@floating-ui/react";
import { useClickOutside as C, useEscapeDismiss as w, useOverlayFocus as T } from "@ryuzaki13/react-foundation-lib/dom";
import { createMissingContextError as E } from "@ryuzaki13/react-foundation-lib/error";
import { createPortal as D } from "react-dom";
var O = {
	popover: "JK2Y7t",
	primary: "_5QtpCJ",
	secondary: "hZuysP"
}, k = n(null);
function A() {
	let e = i(k);
	if (!e) throw E({
		hookName: "usePopoverContext",
		providerName: "Popover"
	});
	return e;
}
//#endregion
//#region src/popover/components/PopoverContent.tsx
var j = ({ children: t, onClose: n, closeOnOutside: i = !0, closeOnEscape: a = !0, disableOutsideClick: s = !1, background: l = "secondary" }) => {
	let { open: p, setOpen: m, refs: h, floatingStyles: g, middlewareData: _, placement: v, arrowRef: y } = A(), b = o(null), x = r((e) => {
		b.current = e, h.setFloating(e);
	}, [h]), S = T({
		active: p,
		initialFocus: "container",
		restoreFocus: !0,
		containerRef: b
	}), E = r(() => {
		p && (m(!1), n?.());
	}, [
		m,
		n,
		p
	]);
	w({
		active: p,
		enabled: a,
		onDismiss: E,
		containerRef: S
	});
	let D = r(() => {
		!p || s || i && E();
	}, [
		p,
		s,
		i,
		E
	]);
	return C([h.floating, h.reference], D), p ? /* @__PURE__ */ u(f, { children: /* @__PURE__ */ d("div", {
		ref: x,
		style: g,
		className: c(O.popover, O[l]),
		role: "dialog",
		"aria-modal": "true",
		tabIndex: -1,
		children: [typeof t == "function" ? t({ setClose: E }) : t, /* @__PURE__ */ u(e, {
			ref: y,
			placement: v,
			middlewareData: _
		})]
	}) }) : null;
}, M = ({ passive: e, children: n }) => {
	let { open: i, setOpen: a, refs: o } = A(), s = r((t) => {
		n.props.onClick && n.props.onClick(t), !t.defaultPrevented && (t.preventDefault(), t.stopPropagation(), !e && a((e) => !e));
	}, [
		n,
		a,
		e
	]);
	return t(n, {
		ref: o.setReference,
		"aria-expanded": i,
		onClick: s
	});
}, N = Object.assign(({ children: e, open: t, defaultOpen: n, onOpenChange: i, placement: a = "bottom" }) => {
	let [c, l] = s(n ?? !1), d = t !== void 0, f = d ? t : c, v = r((e) => {
		let t = typeof e == "function" ? e(f) : e;
		d || l(t), i?.(t);
	}, [
		d,
		i,
		f
	]), b = o(null), { refs: x, floatingStyles: S, middlewareData: C, placement: w } = y({
		open: f,
		onOpenChange: v,
		placement: a,
		middleware: [
			g(8),
			h(),
			_({ padding: 16 }),
			p({ element: b.current })
		],
		whileElementsMounted: m
	});
	return /* @__PURE__ */ u(k.Provider, {
		value: {
			open: f,
			setOpen: v,
			refs: x,
			floatingStyles: S,
			placement: w,
			middlewareData: C,
			arrowRef: b
		},
		children: e
	});
}, {
	Trigger: M,
	Content: j
}), P = {
	tooltipPanel: "sZ0x6w",
	tooltip: "_538Ejd",
	negative: "fqciCO",
	information: "sHkUiQ",
	error: "bpGNoX",
	warning: "tYnRg-",
	success: "_8lflEh"
}, F = ({ content: t, children: n, openOnHover: r = !0, placement: i = "bottom", openDelay: a = 200, closeDelay: f = 100, maxWidth: C, state: w, tooltip: T }) => {
	let [E, O] = s(!1), k = o(null), { refs: A, floatingStyles: j, middlewareData: M, context: N, placement: F } = y({
		open: E,
		onOpenChange: O,
		placement: i,
		middleware: [
			g(8),
			h({
				fallbackAxisSideDirection: "end",
				fallbackPlacements: [
					"top",
					"right",
					"bottom"
				]
			}),
			_({ padding: 16 }),
			p({
				element: k,
				padding: 8
			})
		],
		whileElementsMounted: m
	}), I = b(N, {
		enabled: r,
		move: !1,
		delay: {
			open: a,
			close: f
		}
	}), L = v(N), R = S(N), { getReferenceProps: z, getFloatingProps: B } = x([
		I,
		L,
		R
	]);
	return /* @__PURE__ */ d(l, { children: [/* @__PURE__ */ u("span", {
		ref: A.setReference,
		...z(),
		style: { lineHeight: 1 },
		children: n
	}), E && D(/* @__PURE__ */ d("div", {
		ref: A.setFloating,
		style: {
			...j,
			zIndex: "var(--z-tooltip)",
			maxWidth: C ? `${C}em` : void 0
		},
		...B(),
		role: "tooltip",
		className: c(P.tooltipPanel, T && P.tooltip, w && P[w]),
		children: [t, /* @__PURE__ */ u(e, {
			ref: k,
			placement: F,
			middlewareData: M
		})]
	}), document.body)] });
}, I = ({ x: t, y: n, children: r }) => {
	let i = o(null), { refs: s, floatingStyles: c, middlewareData: l, placement: f } = y({
		strategy: "absolute",
		placement: "top",
		middleware: [
			g(6),
			h(),
			_({ padding: 16 }),
			p({ element: i })
		]
	});
	return a(() => {
		s.setReference && s.setReference({ getBoundingClientRect: () => ({
			x: t,
			y: n,
			width: 0,
			height: 0,
			top: n,
			left: t,
			bottom: n,
			right: t,
			toJSON: () => {}
		}) });
	}, [
		t,
		n,
		s
	]), /* @__PURE__ */ d("div", {
		ref: s.setFloating,
		style: {
			...c,
			position: "absolute",
			pointerEvents: "none"
		},
		className: P.tooltip,
		children: [r, /* @__PURE__ */ u(e, {
			ref: i,
			placement: f,
			middlewareData: l
		})]
	});
};
//#endregion
export { j as a, M as i, F as n, A as o, N as r, I as t };

//# sourceMappingURL=popover-CGU3MlsH.js.map