import { t as e } from "../chunks/ui.module-DHVTOqZ0.js";
import { c as t, d as n, i as r, r as i } from "../chunks/input-CCdBtl-C.js";
import { useCallback as a, useMemo as o, useRef as s } from "react";
import { cn as c, handleKeyboardActivation as l } from "@ryuzaki13/react-foundation-lib/utils";
import { jsx as u, jsxs as d } from "react/jsx-runtime";
import { ReadImageError as f, readImageFile as p } from "@ryuzaki13/react-foundation-lib/file";
var m = {
	control: "EV-Vji",
	fileName: "A5-T93",
	hiddenInput: "V1Rhiv"
};
//#endregion
//#region src/input-image/InputImage.tsx
function h({ value: h, onChange: g, onClear: _, onReadError: v, allowedMime: y, maxBytes: b, readMode: x, label: S, description: C, placeholder: w = "Выберите изображение", disabled: T, size: E, error: D, onClearError: O, className: k }) {
	let A = s(null), { controlId: j, labelId: M, descriptionId: N, errorId: P, describedBy: F } = n({
		hasLabel: S != null,
		hasDescription: !!C,
		hasError: !!D
	}), I = a((e) => x === "array-buffer" ? p(e, {
		allowedMime: y,
		maxBytes: b,
		mode: "array-buffer"
	}) : p(e, {
		allowedMime: y,
		maxBytes: b
	}), [
		y,
		b,
		x
	]), L = o(() => y && y.length > 0 ? y.join(",") : "image/*", [y]), R = a(async (e) => {
		let t = e.target.files?.[0];
		if (t) {
			e.target.value = "", D && O && O();
			try {
				g(await I(t));
			} catch (e) {
				e instanceof f && v && v(e);
			}
		}
	}, [
		I,
		g,
		v,
		D,
		O
	]), z = a(() => {
		A.current?.click();
	}, []);
	return /* @__PURE__ */ d(t, {
		label: S,
		description: C,
		disabled: T,
		className: k,
		size: E,
		error: D,
		controlId: j,
		labelId: M,
		descriptionId: N,
		errorId: P,
		children: [/* @__PURE__ */ u("input", {
			ref: A,
			id: j,
			type: "file",
			accept: L,
			disabled: T,
			className: m.hiddenInput,
			onChange: R,
			tabIndex: -1
		}), /* @__PURE__ */ u(r, {
			endAdornment: _ ? /* @__PURE__ */ u(i, {
				onClick: _,
				disabled: T
			}) : void 0,
			endAdornmentWidth: _ ? "var(--control-height)" : void 0,
			children: ({ controlClassName: t }) => /* @__PURE__ */ u("div", {
				role: "button",
				tabIndex: T ? -1 : 0,
				onClick: z,
				onKeyDown: (e) => l(e, z, { disabled: T }),
				className: c(e.uiInputControl, m.control, t, !!D && "invalid"),
				"data-disabled": T || void 0,
				"aria-invalid": !!D || void 0,
				"aria-disabled": T,
				"aria-labelledby": M,
				"aria-describedby": F,
				children: h ? /* @__PURE__ */ u("span", {
					className: m.fileName,
					children: h.meta.name
				}) : /* @__PURE__ */ u("span", {
					className: e.uiPlaceholder,
					children: w
				})
			})
		})]
	});
}
//#endregion
export { h as InputImage };

//# sourceMappingURL=index.js.map