import { t as e } from "../chunks/clsx.js";
import { twMerge as t } from "./helpers/twMerge.js";
import { useSlots as n } from "./hooks/useSlots.js";
import { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
import { Icon as s } from "@clubmed/trident-icons";
import { jsx as c, jsxs as l } from "react/jsx-runtime";
//#region lib/ui/Dropdown.tsx
function u(e) {
	let [t, s] = o(!1), c = a(null), l = a(t), u = l.current, d = !t && u;
	l.current = t;
	let f = r(() => {
		s((e) => !e);
	}, []), p = r(() => {
		s(!1);
	}, []), m = typeof e == "function" ? e({
		close: p,
		open: t,
		toggle: f
	}) : e, { label: h, children: g } = n(m, ["label"]);
	return i(() => {
		if (!c.current) return;
		let e = c.current.querySelectorAll(".dropdown-panel a[href], .dropdown-panel [data-dropdown-item]"), t = Array.from(e, (e) => {
			let t = () => {
				p();
			};
			return e.addEventListener("click", t), {
				handleItemClick: t,
				item: e
			};
		});
		return () => {
			t.forEach(({ handleItemClick: e, item: t }) => {
				t.removeEventListener("click", e);
			});
		};
	}, [p, m]), i(() => {
		if (!t) return;
		let e = (e) => {
			!c.current || e.composedPath().includes(c.current) || p();
		};
		return document.addEventListener("click", e), () => {
			document.removeEventListener("click", e);
		};
	}, [p, t]), {
		children: g,
		close: p,
		containerRef: c,
		isLeaving: d,
		label: h,
		open: t,
		toggle: f
	};
}
function d({ icon: n = "ArrowOutlinedDown", className: r, children: i, ...a }) {
	let { children: o, containerRef: d, isLeaving: f, label: p, open: m, toggle: h } = u(i);
	return /* @__PURE__ */ l("div", {
		ref: d,
		className: t("flex items-center gap-8 relative", r),
		children: [/* @__PURE__ */ l("button", {
			tabIndex: -1,
			...a,
			className: "flex gap-8 items-center relative",
			onClick: h,
			children: [p, /* @__PURE__ */ c(s, {
				name: n,
				className: "w-30"
			})]
		}), /* @__PURE__ */ c("div", {
			className: t(e("dropdown-panel z-5 flex items-center gap-12 bg-white rounded-16 border-1 border-lightGrey absolute top-[calc(100%+8px)] right-0 text-black p-20 min-w-[120px] origin-center will-change[transform,opacity]", {
				"animate-zoom-in": m,
				"animate-zoom-out": !m && f,
				"opacity-0 scale-90 pointer-events-none": !m && !f
			})),
			children: o
		})]
	});
}
//#endregion
export { d as Dropdown, u as useDropdown };

//# sourceMappingURL=Dropdown.js.map