import { t as e } from "./ui.module-BisoTevy.js";
import { useEffect as t, useEffectEvent as n, useId as r, useState as i } from "react";
import { cn as a } from "@ryuzaki13/react-foundation-lib/utils";
import { XIcon as o } from "lucide-react";
import { jsx as s, jsxs as c } from "react/jsx-runtime";
import { toFiniteNumber as l } from "@ryuzaki13/react-foundation-lib/formatters";
var u = {
	controlLayout: "lRn5ye",
	input: "ce5HAY",
	inputNumber: "_8TObqB",
	controlWithEndAdornment: "Gx3Wbd",
	controlEndAdornment: "cpwaYo",
	endAdornmentGroup: "itlmix",
	clearButton: "aITEGl",
	error: "ekyJIt"
};
//#endregion
//#region src/input/lib/useInputFieldIds.ts
function d({ id: e, hasLabel: t, hasDescription: n, hasError: i }) {
	let a = r(), o = e ?? a, s = t ? `${o}-label` : void 0, c = n ? `${o}-description` : void 0, l = i ? `${o}-error` : void 0;
	return {
		controlId: o,
		labelId: s,
		descriptionId: c,
		errorId: l,
		describedBy: [c, l].filter(Boolean).join(" ") || void 0
	};
}
//#endregion
//#region src/input/Input.tsx
function f({ label: t, controlId: n, labelId: r }) {
	return /* @__PURE__ */ s("label", {
		id: r,
		htmlFor: n,
		className: e.uiLabel,
		children: t
	});
}
function p({ label: t, description: n, size: r, disabled: i, className: o }) {
	let { controlId: l, labelId: u, descriptionId: p } = d({
		hasLabel: t != null,
		hasDescription: !!n
	});
	return /* @__PURE__ */ c("div", {
		className: a(e.uiElement, e.uiSizable, r && e[r], e.disabled, o),
		"aria-disabled": i || void 0,
		children: [
			t && /* @__PURE__ */ s(f, {
				label: t,
				controlId: l,
				labelId: u
			}),
			n && /* @__PURE__ */ s("p", {
				id: p,
				className: e.uiDescription,
				children: n
			}),
			/* @__PURE__ */ s("div", { className: a(e.uiInputControlFake, "skeletonLine") })
		]
	});
}
function m({ label: t, description: n, disabled: r, className: i, error: o, size: l, controlId: d, labelId: p, descriptionId: m, errorId: h, children: g }) {
	return /* @__PURE__ */ c("div", {
		className: a(e.uiElement, e.uiSizable, l && e[l], r && e.disabled, i),
		"aria-disabled": r || void 0,
		children: [
			t && /* @__PURE__ */ s(f, {
				label: t,
				controlId: d,
				labelId: p
			}),
			n && /* @__PURE__ */ s("p", {
				id: m,
				className: e.uiDescription,
				children: n
			}),
			/* @__PURE__ */ c("div", {
				className: u.controlLayout,
				children: [g, o && /* @__PURE__ */ s("p", {
					id: h,
					className: u.error,
					role: "alert",
					children: o
				})]
			})
		]
	});
}
function h({ className: e, endAdornment: t, endAdornmentClassName: n, endAdornmentWidth: r, children: i }) {
	let o = t != null, l = o && r ? { "--input-end-adornment-width": r } : void 0;
	return /* @__PURE__ */ c("div", {
		className: a(u.controlLayout, e),
		style: l,
		children: [i({ controlClassName: o ? u.controlWithEndAdornment : void 0 }), o && /* @__PURE__ */ s("div", {
			className: a(u.controlEndAdornment, n),
			children: t
		})]
	});
}
function g({ onClick: e, disabled: t, className: n, ariaLabel: r = "Очистить значение" }) {
	return /* @__PURE__ */ s("button", {
		type: "button",
		disabled: t || !e,
		className: a(u.clearButton, "flexCenter radiusSm", n),
		onClick: e,
		"aria-label": r,
		children: /* @__PURE__ */ s(o, {})
	});
}
function _(e, t, n) {
	if (n) return n;
	if (e && t) return "calc((var(--control-height) * 2) + var(--space-xs))";
	if (e || t) return "var(--control-height)";
}
function v({ endAdornment: e, onClear: t, disabled: n }) {
	if (!(e == null && !t)) return /* @__PURE__ */ c("div", {
		className: u.endAdornmentGroup,
		children: [e, t && /* @__PURE__ */ s(g, {
			onClick: t,
			disabled: n
		})]
	});
}
function y({ label: t, description: n, disabled: r, className: o, onClear: c, error: l, onClearError: f, onChange: p, value: g, size: y, allowedPattern: b, endAdornment: x, endAdornmentClassName: S, endAdornmentWidth: C, type: w = "text", ...T }) {
	let [E, D] = i(!1), O = (e) => {
		let t = e.target.value;
		b !== void 0 && D(t !== "" && !b.test(t)), p(t), l && f && f();
	}, k = !!(g && g.length > 0), A = k ? l : void 0, { controlId: j, labelId: M, descriptionId: N, errorId: P, describedBy: F } = d({
		id: T.id,
		hasLabel: t != null,
		hasDescription: !!n,
		hasError: !!A
	}), I = k && (!!l || E);
	return /* @__PURE__ */ s(m, {
		label: t,
		description: n,
		disabled: r,
		className: o,
		size: y,
		error: A,
		controlId: j,
		labelId: M,
		descriptionId: N,
		errorId: P,
		children: /* @__PURE__ */ s(h, {
			endAdornment: v({
				endAdornment: x,
				onClear: c,
				disabled: r
			}),
			endAdornmentClassName: S,
			endAdornmentWidth: _(x != null, !!c, C),
			children: ({ controlClassName: t }) => /* @__PURE__ */ s("input", {
				...T,
				id: j,
				type: w,
				disabled: r,
				value: g,
				"aria-invalid": I || void 0,
				"aria-labelledby": M,
				"aria-describedby": F,
				"data-invalid": I ? "" : void 0,
				className: a(e.uiInputControl, u.input, t),
				onChange: O
			})
		})
	});
}
function b({ label: r, description: o, disabled: c, className: f, onClear: p, error: g, onClearError: y, onChange: b, value: x, size: S, endAdornment: C, endAdornmentClassName: w, endAdornmentWidth: T, ...E }) {
	let D = E, { controlId: O, labelId: k, descriptionId: A, errorId: j, describedBy: M } = d({
		id: E.id,
		hasLabel: r != null,
		hasDescription: !!o,
		hasError: !!g
	}), [N, P] = i(() => String(x)), F = n((e) => {
		P(e);
	});
	t(() => {
		F(x !== void 0 && typeof x == "number" && !isNaN(x) ? String(x) : "");
	}, [x]);
	let I = p ? () => {
		P(""), p();
	} : void 0, L = (e) => {
		let t = e.target.value;
		P(t), b(l(t)), g && y && y();
	};
	return /* @__PURE__ */ s(m, {
		label: r,
		description: o,
		disabled: c,
		className: f,
		size: S,
		error: g,
		controlId: O,
		labelId: k,
		descriptionId: A,
		errorId: j,
		children: /* @__PURE__ */ s(h, {
			endAdornment: v({
				endAdornment: C,
				onClear: I,
				disabled: c
			}),
			endAdornmentClassName: w,
			endAdornmentWidth: _(C != null, !!I, T),
			children: ({ controlClassName: t }) => /* @__PURE__ */ s("input", {
				...D,
				id: O,
				type: "number",
				inputMode: "decimal",
				disabled: c,
				value: N,
				"aria-labelledby": k,
				"aria-describedby": M,
				className: a(e.uiInputControl, u.input, u.inputNumber, t),
				onChange: L
			})
		})
	});
}
var x = y;
//#endregion
//#region src/input/InputErrorComponent.tsx
function S({ text: t }) {
	return /* @__PURE__ */ s("div", {
		className: e.uiErrorElement,
		children: t
	});
}
//#endregion
export { b as a, p as c, h as i, d as l, x as n, y as o, g as r, m as s, S as t, u };

//# sourceMappingURL=input-BCJfUdK_.js.map