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

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