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

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