import { n as e } from "../chunks/input-files-TXdXrSAs.js";
import { useCallback as t, useMemo as n, useRef as r, useState as i } from "react";
import { cn as a, handleKeyboardActivation as o } from "@ryuzaki13/react-foundation-lib/utils";
import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
import { UploadIcon as u } from "lucide-react";
import { ReadFileError as d, assertValidAccept as f, assertValidAllowedMime as p, readFile as m } from "@ryuzaki13/react-foundation-lib/file";
var h = {
	zone: "q2D6Pw",
	dragOver: "QVgB0d",
	disabled: "-nyQKp",
	icon: "kY0O9g",
	hint: "F5K1bE"
};
//#endregion
//#region src/drop-zone/DropZone.tsx
function g({ value: g, onChange: _, onChangeError: v, accept: y, allowedMime: b, maxBytes: x, readMode: S, multiple: C = !0, disabled: w, className: T, children: E }) {
	p(b), f(y);
	let D = r(0), O = r(null), [k, A] = i(!1), j = n(() => y && y.length > 0 ? y.join(",") : b && b.length > 0 ? b.join(",") : "*", [b, y]), M = t((e) => S === "array-buffer" ? m(e, {
		allowedMime: b,
		maxBytes: x,
		mode: "array-buffer"
	}) : m(e, {
		allowedMime: b,
		maxBytes: x
	}), [
		b,
		x,
		S
	]), N = t(async (e) => {
		if (w || e.length === 0) return;
		let t = C ? e : e.slice(0, 1), n = [];
		for (let e of t) try {
			let t = await M(e);
			n.push(t);
		} catch (e) {
			e instanceof d && v && v(e);
		}
		n.length > 0 && _(n);
	}, [
		w,
		C,
		_,
		v,
		M
	]), P = t(() => {
		w || O.current?.click();
	}, [w]), F = t((e) => {
		e.preventDefault(), e.stopPropagation(), !w && (D.current += 1, D.current === 1 && A(!0));
	}, [w]), I = t((e) => {
		e.preventDefault(), e.stopPropagation(), !w && (e.dataTransfer.dropEffect = "copy");
	}, [w]), L = t((e) => {
		e.preventDefault(), e.stopPropagation(), !w && (--D.current, D.current === 0 && A(!1));
	}, [w]), R = t(async (e) => {
		if (e.preventDefault(), e.stopPropagation(), D.current = 0, A(!1), w) return;
		let t = Array.from(e.dataTransfer.files);
		await N(t);
	}, [w, N]), z = t(async (e) => {
		let t = Array.from(e.target.files ?? []);
		await N(t), e.target.value = "";
	}, [N]), B = t((e) => {
		o(e, P, { disabled: w });
	}, [w, P]);
	return /* @__PURE__ */ l("div", { children: [
		/* @__PURE__ */ c("input", {
			ref: O,
			type: "file",
			hidden: !0,
			disabled: w,
			multiple: C,
			accept: j,
			onChange: z
		}),
		/* @__PURE__ */ c("div", {
			className: a(h.zone, k && h.dragOver, w && h.disabled, T),
			onClick: P,
			onKeyDown: B,
			onDragEnter: F,
			onDragOver: I,
			onDragLeave: L,
			onDrop: R,
			role: "button",
			tabIndex: w ? -1 : 0,
			"aria-disabled": w,
			children: E ?? /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ c(u, { className: h.icon }), /* @__PURE__ */ c("span", {
				className: h.hint,
				children: C ? "Перетащите файлы сюда или нажмите для выбора" : "Перетащите файл сюда или нажмите для выбора"
			})] })
		}),
		/* @__PURE__ */ c(e, {
			files: g,
			onChange: _
		})
	] });
}
//#endregion
export { g as DropZone };

//# sourceMappingURL=index.js.map