import { t as e } from "./ui.module-DHVTOqZ0.js";
import { t } from "./grid-dI94AAbi.js";
import { a as n, c as r, d as i, i as a } from "./input-CCdBtl-C.js";
import { t as o } from "./separator-B72Aq-6a.js";
import { forwardRef as s, useEffect as c, useMemo as l, useRef as u, useState as d } from "react";
import { cn as f } from "@ryuzaki13/react-foundation-lib/utils";
import { FloatingFocusManager as p, FloatingPortal as m } from "@floating-ui/react";
import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
import { ChevronDownIcon as v } from "lucide-react";
import { useFloatingListbox as y } from "@ryuzaki13/react-foundation-lib/hooks";
import { normalizeTextToLower as b } from "@ryuzaki13/react-foundation-lib/formatters";
import { AnimatePresence as x, motion as S } from "motion/react";
//#region src/picker/PickerField.tsx
function C({ id: e, label: t, description: n, disabled: a, size: o, className: s, error: c, children: l }) {
	let { controlId: u, labelId: d, descriptionId: f, errorId: p, describedBy: m } = i({
		id: e,
		hasLabel: t != null,
		hasDescription: !!n,
		hasError: !!c
	});
	return /* @__PURE__ */ g(r, {
		label: t,
		description: n,
		disabled: a,
		size: o,
		className: s,
		error: c,
		controlId: u,
		labelId: d,
		descriptionId: f,
		errorId: p,
		children: l({
			controlId: u,
			labelId: d,
			descriptionId: f,
			errorId: p,
			describedBy: m
		})
	});
}
var w = {
	popupLayout: "DRJ4hy",
	popupBody: "U4CULi",
	status: "bupTWA",
	statusError: "GkeyGF",
	triggerContainer: "_8F667e",
	selectionActionButton: "OGMk6I"
};
//#endregion
//#region src/picker/PickerPopup.tsx
function T(e) {
	e.stopPropagation();
}
function E({ open: e, context: t, floatingStyles: n, listId: r, labelId: i, popupAriaLabel: a, descriptionId: s, activeOptionId: c, ariaMultiselectable: l, popupRole: u = "listbox", setFloating: d, getFloatingProps: h, onKeyDown: v, initialFocus: y = -1, returnFocus: b = !1, tabIndex: C = 0, className: E, maxWidth: D, layoutClassName: O, headerClassName: k, bodyClassName: A, header: j, children: M }) {
	return /* @__PURE__ */ g(x, { children: e && /* @__PURE__ */ g(m, { children: /* @__PURE__ */ g(p, {
		context: t,
		modal: !1,
		initialFocus: y,
		returnFocus: b,
		children: /* @__PURE__ */ g(S.div, {
			ref: d,
			style: {
				...n,
				maxWidth: D
			},
			initial: {
				opacity: 0,
				scale: .95
			},
			animate: {
				opacity: 1,
				scale: 1
			},
			exit: {
				opacity: 0,
				scale: .95
			},
			...h({
				id: r,
				role: u,
				tabIndex: C,
				"aria-labelledby": i,
				"aria-label": i ? void 0 : a,
				"aria-describedby": s,
				"aria-activedescendant": c,
				"aria-multiselectable": l || void 0,
				onMouseDown: T,
				onKeyDown: v,
				className: E
			}),
			children: /* @__PURE__ */ _("div", {
				className: f(w.popupLayout, O),
				children: [j ? /* @__PURE__ */ _("div", {
					className: k,
					children: [j, /* @__PURE__ */ g(o, { className: "marginBlockSm" })]
				}) : /* @__PURE__ */ g("div", {}), /* @__PURE__ */ g("div", {
					className: f(w.popupBody, A),
					children: M
				})]
			})
		})
	}) }) });
}
//#endregion
//#region src/picker/PickerSelectionToolbar.tsx
function D({ onSelectAll: e, onDeselectAll: n, selectAllButtonRef: r }) {
	return /* @__PURE__ */ _(t.Container, {
		gap: "xs",
		templateColumns: "1fr 1fr",
		children: [/* @__PURE__ */ g("button", {
			ref: r,
			type: "button",
			className: w.selectionActionButton,
			onClick: e,
			"data-ui": "picker-select-all",
			"data-action": "select-all",
			children: "Выбрать все"
		}), /* @__PURE__ */ g("button", {
			type: "button",
			className: w.selectionActionButton,
			onClick: n,
			"data-ui": "picker-deselect-all",
			"data-action": "deselect-all",
			children: "Снять выбор"
		})]
	});
}
//#endregion
//#region src/picker/PickerStatus.tsx
function O({ emptyState: t, errorState: n }) {
	let r = n ?? t;
	return r == null ? null : /* @__PURE__ */ g("div", {
		className: f(e.uiPopupOption, w.status, n !== void 0 && w.statusError),
		"aria-disabled": !0,
		children: r
	});
}
//#endregion
//#region src/picker/PickerTriggerActions.tsx
function k({ open: t, disabled: n, children: r, onToggleMouseDown: i, onToggleClick: a, openAriaLabel: o = "Открыть список", closeAriaLabel: s = "Закрыть список" }) {
	return /* @__PURE__ */ _("div", {
		className: e.uiToggleButtonContainer,
		"data-disabled": n || void 0,
		children: [
			r,
			/* @__PURE__ */ g("div", { className: e.uiButtonSeparator }),
			/* @__PURE__ */ g("button", {
				type: "button",
				"aria-label": t ? s : o,
				className: e.uiToggleButton,
				onMouseDown: i,
				onClick: a,
				children: /* @__PURE__ */ g(v, { className: f(e.uiToggleIcon, t && e.uiToggleIconOpen) })
			})
		]
	});
}
//#endregion
//#region src/picker/PickerTriggerInput.tsx
var A = s(({ rootRef: t, endAdornment: r, overlay: i, rootClassName: o, inputClassName: s, isLoading: c, ...l }, u) => /* @__PURE__ */ g("div", {
	ref: t,
	className: f(e.uiInputContainer, w.triggerContainer, o),
	children: c ? /* @__PURE__ */ g(n, {}) : /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g(a, {
		endAdornment: r,
		children: ({ controlClassName: t }) => /* @__PURE__ */ g("input", {
			...l,
			ref: u,
			className: f(e.uiInputWithToggle, t, s)
		})
	}), i] })
}));
A.displayName = "PickerTriggerInput";
//#endregion
//#region src/picker/model/createPickerTriggerPolicy.ts
function j(e) {
	switch (e) {
		case "search-single": return {
			focusFloatingOnOpen: !1,
			restoreFocusOnClose: !1,
			resetQueryOnClose: !0,
			shouldOpenOnTriggerClick: () => !1,
			shouldOpenOnInputChange: (e) => !e,
			shouldFocusReferenceOnToggle: (e) => !e,
			shouldSelectTriggerTextOnFocus: ({ open: e, currentQuery: t, hasDisplayValue: n }) => !e && t.length === 0 && n
		};
		case "search-multi": return {
			focusFloatingOnOpen: !1,
			restoreFocusOnClose: !1,
			resetQueryOnClose: !0,
			shouldOpenOnTriggerClick: () => !1,
			shouldOpenOnInputChange: (e) => !e,
			shouldFocusReferenceOnToggle: (e) => !e,
			shouldSelectTriggerTextOnFocus: () => !1
		};
		default: return {
			focusFloatingOnOpen: !0,
			restoreFocusOnClose: !0,
			resetQueryOnClose: !1,
			shouldOpenOnTriggerClick: (e) => !e,
			shouldOpenOnInputChange: () => !1,
			shouldFocusReferenceOnToggle: () => !1,
			shouldSelectTriggerTextOnFocus: () => !1
		};
	}
}
//#endregion
//#region src/picker/model/extractPickerTextContent.ts
function M(e) {
	if (typeof e == "string" || typeof e == "number") return String(e);
	if (Array.isArray(e)) {
		let t = e.map(M).filter((e) => !!e);
		return t.length ? t.join(" ") : void 0;
	}
}
//#endregion
//#region src/picker/model/usePickerDefaultFilter.ts
function N(e) {
	return b((Array.isArray(e) ? e : [e]).filter(Boolean).join(" "));
}
function P({ options: e, query: t, enabled: n = !0, getSearchText: r }) {
	let i = b(t);
	return l(() => !n || !i ? [...e] : e.filter((e) => N(r(e)).includes(i)), [
		n,
		r,
		i,
		e
	]);
}
//#endregion
//#region src/picker/model/usePickerFloatingListbox.ts
function F(e) {
	let t = e.triggerMode ? j(e.triggerMode) : void 0;
	return y({
		...e,
		focusFloatingOnOpen: e.focusFloatingOnOpen ?? t?.focusFloatingOnOpen,
		restoreFocusOnClose: e.restoreFocusOnClose ?? t?.restoreFocusOnClose
	});
}
//#endregion
//#region src/picker/model/usePickerQuery.ts
function I({ query: e, defaultQuery: t, onQuery: n, resetOnClose: r, triggerMode: i }) {
	let a = e !== void 0, [o, s] = d(t ?? ""), c = a ? e ?? "" : o, l = r ?? (!i || j(i).resetQueryOnClose), u = (e) => {
		a || s(e), n?.(e);
	};
	return {
		query: c,
		setQuery: u,
		clearQuery: () => u(""),
		resetQueryOnClose: l
	};
}
//#endregion
//#region src/picker/model/usePickerSelectionLifecycle.ts
function L({ value: e, open: t, onCommit: n, onOpen: r, onClose: i, isEqual: a }) {
	let o = u(!1), [s, l] = d(e);
	return c(() => {
		o.current && !t && (a(s, e) || n(s), i?.(s)), o.current = t;
	}, [
		s,
		a,
		i,
		n,
		t,
		e
	]), {
		draftValue: s,
		setDraftValue: l,
		prepareOpen: () => {
			l(e), r?.();
		}
	};
}
//#endregion
//#region src/picker/model/usePickerTriggerController.ts
function R(e) {
	requestAnimationFrame(() => {
		e.current?.focus();
	});
}
function z({ mode: e, open: t, currentQuery: n, hasDisplayValue: r, inputRef: i, setQuery: a, openList: o, close: s, toggleOpen: c, onBeforeOpen: l }) {
	let u = j(e), d = () => {
		if (l?.(), o) {
			o();
			return;
		}
		c?.();
	}, f = () => {
		if (s) {
			s();
			return;
		}
		c?.();
	}, p = () => {
		t ? f() : d(), u.shouldFocusReferenceOnToggle(t) && R(i);
	};
	return {
		policy: u,
		handleTriggerInputChange: (e) => {
			a?.(e), u.shouldOpenOnInputChange(t) && d();
		},
		handleTriggerClick: () => {
			u.shouldOpenOnTriggerClick(t) && d();
		},
		handleTriggerFocus: (e) => {
			u.shouldSelectTriggerTextOnFocus({
				open: t,
				currentQuery: n,
				hasDisplayValue: r
			}) && requestAnimationFrame(() => {
				e.select();
			});
		},
		handleToggleMouseDown: (e) => {
			e.preventDefault();
		},
		handleToggleClick: () => {
			p();
		},
		handleTriggerKeyDown: ({ event: e, onActivateWhenOpen: n, enableSpaceActivation: r = !1, enableClosedArrowDownOpen: i = !1, suppressClosedArrowUp: a = !1 }) => {
			if (!t && a && e.key === "ArrowUp") {
				e.preventDefault();
				return;
			}
			if (!t && i && e.key === "ArrowDown") {
				e.preventDefault(), p();
				return;
			}
			if (e.key === "Enter") {
				e.preventDefault(), t ? n?.() : p();
				return;
			}
			r && e.key === " " && (e.preventDefault(), t ? n?.() : p());
		},
		toggleTrigger: p
	};
}
//#endregion
export { P as a, A as c, D as d, E as f, F as i, k as l, L as n, M as o, C as p, I as r, j as s, z as t, O as u };

//# sourceMappingURL=picker-CrRdwdA5.js.map