import { t as e } from "./ui.module-BisoTevy.js";
import { i as t, l as n, s as r } from "./input-CZLUUggm.js";
import { t as i } from "./separator-B72Aq-6a.js";
import { forwardRef as a, useEffect as o, useEffectEvent as s, useMemo as c, useRef as l, useState as u } from "react";
import { cn as d } from "@ryuzaki13/react-foundation-lib/utils";
import { normalizeTextToLower as f } from "@ryuzaki13/react-foundation-lib/formatters";
import { ChevronDownIcon as p } from "lucide-react";
import { jsx as m, jsxs as h } from "react/jsx-runtime";
import { FloatingFocusManager as g, FloatingPortal as _ } from "@floating-ui/react";
import { useFloatingListbox as v } from "@ryuzaki13/react-foundation-lib/hooks";
import { AnimatePresence as y, motion as b } from "motion/react";
//#region src/picker/PickerField.tsx
function x({ id: e, label: t, description: i, disabled: a, size: o, className: s, error: c, children: l }) {
	let { controlId: u, labelId: d, descriptionId: f, errorId: p, describedBy: h } = n({
		id: e,
		hasLabel: t != null,
		hasDescription: !!i,
		hasError: !!c
	});
	return /* @__PURE__ */ m(r, {
		label: t,
		description: i,
		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 S = {
	popupLayout: "DRJ4hy",
	popupBody: "U4CULi",
	status: "bupTWA",
	statusError: "GkeyGF",
	triggerContainer: "_8F667e"
};
//#endregion
//#region src/picker/PickerPopup.tsx
function C(e) {
	e.stopPropagation();
}
function w({ open: e, context: t, floatingStyles: n, listId: r, labelId: a, descriptionId: o, activeOptionId: s, setFloating: c, getFloatingProps: l, onKeyDown: u, initialFocus: f = -1, returnFocus: p = !1, tabIndex: v = 0, className: x, maxWidth: w, layoutClassName: T, headerClassName: E, bodyClassName: D, header: O, children: k }) {
	return /* @__PURE__ */ m(y, { children: e && /* @__PURE__ */ m(_, { children: /* @__PURE__ */ m(g, {
		context: t,
		modal: !1,
		initialFocus: f,
		returnFocus: p,
		children: /* @__PURE__ */ m(b.div, {
			ref: c,
			style: {
				...n,
				maxWidth: w
			},
			initial: {
				opacity: 0,
				scale: .95
			},
			animate: {
				opacity: 1,
				scale: 1
			},
			exit: {
				opacity: 0,
				scale: .95
			},
			...l({
				id: r,
				tabIndex: v,
				"aria-labelledby": a,
				"aria-describedby": o,
				"aria-activedescendant": s,
				onMouseDown: C,
				onKeyDown: u,
				className: x
			}),
			children: /* @__PURE__ */ h("div", {
				className: d(S.popupLayout, T),
				children: [O ? /* @__PURE__ */ h("div", {
					className: E,
					children: [O, /* @__PURE__ */ m(i, { className: "marginBlockSm" })]
				}) : /* @__PURE__ */ m("div", {}), /* @__PURE__ */ m("div", {
					className: d(S.popupBody, D),
					children: k
				})]
			})
		})
	}) }) });
}
//#endregion
//#region src/picker/PickerStatus.tsx
function T({ emptyState: t, loadingState: n, errorState: r }) {
	let i = r ?? n ?? t;
	return i == null ? null : /* @__PURE__ */ m("div", {
		className: d(e.uiPopupOption, S.status, r !== void 0 && S.statusError),
		"aria-disabled": !0,
		children: i
	});
}
//#endregion
//#region src/picker/PickerTriggerActions.tsx
function E({ 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: d(e.uiToggleIcon, t && e.uiToggleIconOpen) })
			})
		]
	});
}
//#endregion
//#region src/picker/PickerTriggerInput.tsx
var D = a(({ rootRef: n, endAdornment: r, overlay: i, rootClassName: a, inputClassName: o, ...s }, c) => /* @__PURE__ */ h("div", {
	ref: n,
	className: d(e.uiInputContainer, S.triggerContainer, a),
	children: [/* @__PURE__ */ m(t, {
		endAdornment: r,
		children: ({ controlClassName: t }) => /* @__PURE__ */ m("input", {
			...s,
			ref: c,
			className: d(e.uiInputWithToggle, t, o)
		})
	}), i]
}));
D.displayName = "PickerTriggerInput";
//#endregion
//#region src/picker/model/createPickerTriggerPolicy.ts
function O(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 k(e) {
	if (typeof e == "string" || typeof e == "number") return String(e);
	if (Array.isArray(e)) {
		let t = e.map(k).filter((e) => !!e);
		return t.length ? t.join(" ") : void 0;
	}
}
//#endregion
//#region src/picker/model/usePickerDefaultFilter.ts
function A(e) {
	return f((Array.isArray(e) ? e : [e]).filter(Boolean).join(" "));
}
function j({ options: e, query: t, enabled: n = !0, getSearchText: r }) {
	let i = f(t);
	return c(() => !n || !i ? [...e] : e.filter((e) => A(r(e)).includes(i)), [
		n,
		r,
		i,
		e
	]);
}
//#endregion
//#region src/picker/model/usePickerFloatingListbox.ts
function M(e) {
	let t = e.triggerMode ? O(e.triggerMode) : void 0;
	return v({
		...e,
		focusFloatingOnOpen: e.focusFloatingOnOpen ?? t?.focusFloatingOnOpen,
		restoreFocusOnClose: e.restoreFocusOnClose ?? t?.restoreFocusOnClose
	});
}
//#endregion
//#region src/picker/model/usePickerQuery.ts
function N({ open: e, query: t, defaultQuery: n, onQuery: r, resetOnClose: i, triggerMode: a }) {
	let c = l(!1), d = t !== void 0, [f, p] = u(n ?? ""), m = d ? t ?? "" : f, h = s(() => p("")), g = i ?? (a ? O(a).resetQueryOnClose : !0);
	o(() => {
		c.current && !e && g && (d || h(), r?.("")), c.current = e;
	}, [
		d,
		r,
		e,
		g
	]);
	let _ = (e) => {
		d || p(e), r?.(e);
	};
	return {
		query: m,
		setQuery: _,
		clearQuery: () => _("")
	};
}
//#endregion
//#region src/picker/model/usePickerSelectionLifecycle.ts
function P({ value: e, open: t, onCommit: n, onOpen: r, onClose: i, isEqual: a }) {
	let c = l(!1), [d, f] = u(e), p = s((e) => f(e));
	return o(() => {
		t || p(e);
	}, [t, e]), o(() => {
		c.current && !t && (a(d, e) || n(d), i?.(d)), c.current = t;
	}, [
		d,
		a,
		i,
		n,
		t,
		e
	]), {
		draftValue: d,
		setDraftValue: f,
		prepareOpen: () => {
			f(e), r?.();
		}
	};
}
//#endregion
//#region src/picker/model/usePickerTriggerController.ts
function F(e) {
	requestAnimationFrame(() => {
		e.current?.focus();
	});
}
function I({ mode: e, open: t, currentQuery: n, hasDisplayValue: r, inputRef: i, setQuery: a, openList: o, close: s, toggleOpen: c, onBeforeOpen: l }) {
	let u = O(e), d = () => {
		if (l?.(), o) {
			o();
			return;
		}
		c?.();
	}, f = () => {
		if (s) {
			s();
			return;
		}
		c?.();
	}, p = () => {
		t ? f() : d(), u.shouldFocusReferenceOnToggle(t) && F(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 { j as a, D as c, w as d, x as f, M as i, E as l, P as n, k as o, N as r, O as s, I as t, T as u };

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