import { cx as e } from "../../../theme/tools.js";
import { Button as t } from "../../../atomic/atoms/button/Button.js";
import { ChevronDownIcon as n } from "../../../atomic/organisms/sidebar/icons.js";
import { container as r, triggerIcon as i, triggerIconOpen as a } from "./backofficeRelationsMenu.css.js";
import { useEffect as o, useId as s, useRef as c, useState as l } from "react";
import { jsx as u, jsxs as d } from "react/jsx-runtime";
import { useTranslation as f } from "react-i18next";
import p from "@plumile/router/routing/Link.js";
//#region src/backoffice/molecules/backoffice_relations_menu/BackofficeRelationsMenu.tsx
var m = ({ label: m, items: h }) => {
	let { t: g } = f("ui"), _ = m ?? g("backoffice.relationsMenu.label"), [v, y] = l(!1), b = c(null), x = c(null), S = c(null), C = s();
	if (o(() => {
		if (!v) return;
		window.setTimeout(() => {
			S.current?.focus();
		}, 0);
		let e = (e) => {
			e.target instanceof Node && (b.current?.contains(e.target) || y(!1));
		};
		return document.addEventListener("pointerdown", e), () => {
			document.removeEventListener("pointerdown", e);
		};
	}, [v]), o(() => {
		if (!v) return;
		let e = (e) => {
			e.key === "Escape" && (y(!1), x.current?.focus());
		};
		return document.addEventListener("keydown", e), () => {
			document.removeEventListener("keydown", e);
		};
	}, [v]), h.length === 0) return /* @__PURE__ */ u(t, {
		type: "button",
		variant: "secondary",
		size: "small",
		disabled: !0,
		children: _
	});
	let w;
	return v && (w = C), /* @__PURE__ */ d("div", {
		className: r,
		ref: b,
		children: [/* @__PURE__ */ d(t, {
			ref: x,
			type: "button",
			variant: "secondary",
			size: "small",
			onClick: () => {
				y((e) => !e);
			},
			"aria-expanded": v,
			"aria-controls": w,
			children: [_, /* @__PURE__ */ u(n, {
				size: 14,
				className: e(i, { [a]: v })
			})]
		}), v && /* @__PURE__ */ u("nav", {
			className: "_16f61fj3 txvbqb13hu txvbqb13jn txvbqb18ub txvbqbryx txvbqbvjh txvbqb1b7z txvbqb28o txvbqb2sj txvbqb1d9 txvbqb2uc txvbqbegi txvbqbww8 txvbqbfpn txvbqbh4x txvbqbhd8 txvbqb1att",
			id: C,
			"aria-label": _,
			children: h.map((e, t) => {
				let n;
				return t === 0 && (n = S), /* @__PURE__ */ d(p, {
					ref: n,
					to: e.href,
					className: "_16f61fj6 _16f61fj4 txvbqb10mx txvbqb11ki txvbqb12hq txvbqbxtt txvbqbfpn txvbqbey txvbqblt7 txvbqbhdl txvbqb2tz txvbqb1bg1 txvbqb3f txvbqb9j txvbqbwlr _16f61fj5 txvbqb1ct1",
					onClick: (t) => {
						y(!1), (e.onClick?.(t))?.catch(() => {});
					},
					children: [/* @__PURE__ */ u("span", {
						className: "_16f61fj7 txvbqbfpn txvbqbey txvbqbhdl txvbqbv7x txvbqbws9",
						children: e.label
					}), e.count != null && /* @__PURE__ */ u("span", {
						className: "_16f61fj8 txvbqb96 txvbqb1bg5 txvbqbh6d",
						children: e.count
					})]
				}, e.id);
			})
		})]
	});
};
//#endregion
export { m as BackofficeRelationsMenu, m as default };

//# sourceMappingURL=BackofficeRelationsMenu.js.map