import { t as e } from "./ui.module-DHVTOqZ0.js";
import { useId as t, useLayoutEffect as n, useRef as r, useState as i } from "react";
import { cn as a } from "@ryuzaki13/react-foundation-lib/utils";
import { jsx as o, jsxs as s } from "react/jsx-runtime";
import { XIcon as c } from "lucide-react";
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: n, hasDescription: r, hasError: i }) {
	let a = t(), o = e ?? a, s = n ? `${o}-label` : void 0, c = r ? `${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__ */ o("label", {
		id: r,
		htmlFor: n,
		className: e.uiLabel,
		children: t
	});
}
function p() {
	return /* @__PURE__ */ o("div", { className: a(e.uiInputControlFake, "skeletonLine") });
}
function m({ label: t, description: n, size: r, disabled: i, isLoading: c, className: l }) {
	let { controlId: u, labelId: p, descriptionId: m } = d({
		hasLabel: t != null,
		hasDescription: !!n
	});
	return /* @__PURE__ */ s("div", {
		className: a(e.uiElement, e.uiSizable, r && e[r], e.disabled, l),
		"aria-disabled": i || void 0,
		children: [
			t && /* @__PURE__ */ o(f, {
				label: t,
				controlId: u,
				labelId: p
			}),
			n && /* @__PURE__ */ o("p", {
				id: m,
				className: e.uiDescription,
				children: n
			}),
			/* @__PURE__ */ o("div", { className: a(e.uiInputControlFake, c && "skeletonLine") })
		]
	});
}
function h(e) {
	return /* @__PURE__ */ o(m, {
		...e,
		isLoading: !0
	});
}
function g({ label: t, description: n, disabled: r, className: i, error: c, size: l, controlId: d, labelId: p, descriptionId: m, errorId: h, required: g, children: _ }) {
	return /* @__PURE__ */ s("div", {
		className: a(e.uiElement, e.uiSizable, l && e[l], r && e.disabled, g && e.required, i),
		"aria-disabled": r || void 0,
		children: [
			t && /* @__PURE__ */ o(f, {
				label: t,
				controlId: d,
				labelId: p
			}),
			n && /* @__PURE__ */ o("p", {
				id: m,
				className: e.uiDescription,
				children: n
			}),
			/* @__PURE__ */ s("div", {
				className: u.controlLayout,
				children: [_, c && /* @__PURE__ */ o("p", {
					id: h,
					className: u.error,
					role: "alert",
					children: c
				})]
			})
		]
	});
}
function _({ className: e, endAdornment: t, endAdornmentClassName: n, endAdornmentWidth: r, children: i }) {
	let c = t != null, l = c && r ? { "--input-end-adornment-width": r } : void 0;
	return /* @__PURE__ */ s("div", {
		className: a(u.controlLayout, e),
		style: l,
		children: [i({ controlClassName: c ? u.controlWithEndAdornment : void 0 }), c && /* @__PURE__ */ o("div", {
			className: a(u.controlEndAdornment, n),
			children: t
		})]
	});
}
function v({ onClick: e, disabled: t, className: n, ariaLabel: r = "Очистить значение" }) {
	return /* @__PURE__ */ o("button", {
		type: "button",
		disabled: t || !e,
		className: a(u.clearButton, n),
		onClick: e,
		"aria-label": r,
		children: /* @__PURE__ */ o(c, {})
	});
}
function y(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 b({ endAdornment: e, onClear: t, disabled: n }) {
	if (!(e == null && !t)) return /* @__PURE__ */ s("div", {
		className: u.endAdornmentGroup,
		children: [e, t && /* @__PURE__ */ o(v, {
			onClick: t,
			disabled: n
		})]
	});
}
function x({ label: t, description: n, disabled: r, className: s, onClear: c, error: l, onClearError: f, onChange: p, value: m, size: h, allowedPattern: v, endAdornment: x, endAdornmentClassName: S, endAdornmentWidth: C, type: w = "text", ...T }) {
	let [E, D] = i(!1), O = (e) => {
		let t = e.target.value;
		v !== void 0 && D(t !== "" && !v.test(t)), p(t), l && f && f();
	}, k = !!(m && m.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), L = b({
		endAdornment: x,
		onClear: c,
		disabled: r || !k
	}), R = y(x != null, !!c, C);
	return /* @__PURE__ */ o(g, {
		label: t,
		description: n,
		disabled: r,
		required: T.required,
		className: s,
		size: h,
		error: A,
		controlId: j,
		labelId: M,
		descriptionId: N,
		errorId: P,
		children: /* @__PURE__ */ o(_, {
			endAdornment: L,
			endAdornmentClassName: S,
			endAdornmentWidth: R,
			children: ({ controlClassName: t }) => /* @__PURE__ */ o("input", {
				...T,
				id: j,
				type: w,
				disabled: r,
				value: m,
				"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 S({ label: t, description: i, disabled: s, className: c, onClear: f, error: p, onClearError: m, onChange: h, value: v, size: x, endAdornment: S, endAdornmentClassName: C, endAdornmentWidth: w, ...T }) {
	let E = T, { controlId: D, labelId: O, descriptionId: k, errorId: A, describedBy: j } = d({
		id: T.id,
		hasLabel: t != null,
		hasDescription: !!i,
		hasError: !!p
	}), M = r(null), N = r(null), P = v !== void 0 && typeof v == "number" && !isNaN(v) ? String(v) : "";
	n(() => {
		let e = N.current;
		if (e && Object.is(e.value, v)) {
			M.current && M.current.value !== e.raw && (M.current.value = e.raw);
			return;
		}
		N.current = null, M.current && M.current.value !== P && (M.current.value = P);
	}, [P, v]);
	let F = f ? () => {
		f();
	} : void 0, I = (e) => {
		let t = e.target.value, n = l(t);
		N.current = {
			value: n,
			raw: t
		}, h(n), p && m && m();
	}, L = b({
		endAdornment: S,
		onClear: F,
		disabled: s
	}), R = y(S != null, !!F, w);
	return /* @__PURE__ */ o(g, {
		label: t,
		description: i,
		disabled: s,
		required: T.required,
		className: c,
		size: x,
		error: p,
		controlId: D,
		labelId: O,
		descriptionId: k,
		errorId: A,
		children: /* @__PURE__ */ o(_, {
			endAdornment: L,
			endAdornmentClassName: C,
			endAdornmentWidth: R,
			children: ({ controlClassName: t }) => /* @__PURE__ */ o("input", {
				...E,
				ref: M,
				id: D,
				type: "number",
				inputMode: "decimal",
				disabled: s,
				defaultValue: P,
				"aria-labelledby": O,
				"aria-describedby": j,
				className: a(e.uiInputControl, u.input, u.inputNumber, t),
				onChange: I
			})
		})
	});
}
var C = x;
//#endregion
//#region src/input/InputErrorComponent.tsx
function w({ text: t }) {
	return /* @__PURE__ */ o("div", {
		className: e.uiErrorElement,
		children: t
	});
}
//#endregion
export { p as a, g as c, d, u as f, _ as i, m as l, C as n, S as o, v as r, x as s, w as t, h as u };

//# sourceMappingURL=input-CCdBtl-C.js.map