import { jsx as l, jsxs as b } from "react/jsx-runtime";
import { t as T } from "../../classix-DG18itHa.js";
import { useRef as j, useState as k } from "react";
import { Button as x } from "../button/index.js";
import { Icon as A } from "../icon/index.js";
import '../../assets/index19.css';const R = "_dropzone_1rpsf_1", w = "_dragging_1rpsf_19", B = "_minimal_1rpsf_23", m = {
  dropzone: R,
  dragging: w,
  minimal: B
}, S = ({
  accepts: z,
  label: D = "Select files",
  maxFileSize: g,
  multiple: d = !1,
  onChange: i,
  onValidation: f,
  variant: a = "default",
  ..._
}) => {
  const u = j(null), [y, o] = k(!1), c = (e) => {
    e.preventDefault(), e.stopPropagation();
  }, F = (e) => {
    const t = u.current;
    if (!t) return;
    const s = new DataTransfer();
    for (const r of e) s.items.add(r);
    t.files = s.files, i == null || i({
      target: t,
      currentTarget: t
    });
  }, v = (e) => {
    const {
      validFiles: t,
      emptyFiles: s,
      oversizedFiles: r
    } = e.reduce((p, n) => (n.size === 0 ? p.emptyFiles.push(n) : g && n.size > g ? p.oversizedFiles.push(n) : p.validFiles.push(n), p), {
      validFiles: [],
      emptyFiles: [],
      oversizedFiles: []
    });
    return (s.length > 0 || r.length > 0) && (f == null || f(s, r)), t;
  }, h = (e) => {
    c(e), o(!1);
    const t = Array.from(e.dataTransfer.files ?? []), s = v(t);
    if (s.length === 0) return;
    const r = d ? s : s.slice(0, 1);
    F(r);
  }, I = (e) => {
    const t = Array.from(e.target.files ?? []), s = v(t);
    if (s.length === t.length) {
      i == null || i(e);
      return;
    }
    const r = d ? s : s.slice(0, 1);
    F(r);
  };
  return /* @__PURE__ */ l("div", { className: T(m.dropzone, m[a], y && m.dragging), onDragEnter: (e) => {
    c(e), o(!0);
  }, onDragOver: (e) => {
    c(e), o(!0);
  }, onDragLeave: (e) => {
    c(e), o(!1);
  }, onDrop: h, ..._, "data-component": "dropzone", children: /* @__PURE__ */ b("label", { children: [
    /* @__PURE__ */ l("input", { accept: z, hidden: !0, multiple: d, onChange: I, ref: u, type: "file" }),
    /* @__PURE__ */ l(A, { name: "upload", size: a === "minimal" ? "medium" : "large" }),
    /* @__PURE__ */ l("br", {}),
    a !== "minimal" && /* @__PURE__ */ l(x, { onClick: () => {
      var e;
      return (e = u.current) == null ? void 0 : e.click();
    }, type: "button", children: D })
  ] }) });
};
export {
  S as Dropzone
};
//# sourceMappingURL=index.js.map
