import { jsx as u } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { useState as x, useRef as D, useCallback as a, useMemo as R, useEffect as M } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { UploadedFile as N } from "./components/UploadedFile.js";
import { Dropzone as h } from "./components/Dropzone.js";
import { validationErrors as i, BASE_CLASS as y } from "./constants.js";
/* empty css               */
import { fixedForwardRef as C } from "../../../../utils/preact/fixedForwardRef.js";
import O from "../../../../core/Context/preact/useCoreContext.js";
import { isFunction as T } from "../../../../utils/value/is.js";
const j = C(({ onChange: c, mapError: n, onDelete: m, ...f }, L) => {
  const [e, d] = x([]), p = D(e), l = e[0], { i18n: r } = O(), { disabled: s } = f, E = a(
    (o) => {
      switch (o) {
        case i.DISALLOWED_FILE_TYPE:
          return r.get("common.inputs.file.errors.disallowedType");
        case i.FILE_REQUIRED:
          return r.get("common.inputs.file.errors.required");
        case i.TOO_MANY_FILES:
          return r.get("common.inputs.file.errors.tooMany");
        case i.VERY_LARGE_FILE:
          return r.get("common.inputs.file.errors.tooLarge");
        case i.INVALID_DIMENSIONS:
          return r.get("common.inputs.file.errors.invalidDimensions");
      }
      return "";
    },
    [r]
  ), _ = R(() => T(n) ? n : E, [n, E]), S = a(
    (o) => {
      s || (d((t) => {
        const F = t.findIndex((A) => A === o);
        if (F < 0)
          return t;
        const [...I] = t;
        return I.splice(F, 1), I;
      }), m?.());
    },
    [s, m]
  ), g = a(
    (o) => {
      s || d((t) => t.length === 0 && o.length === 0 ? t : o);
    },
    [s]
  );
  return M(() => {
    p.current !== e && (p.current = e, c?.([...e]));
  }, [e, c]), /* @__PURE__ */ u("div", {
    className: y,
    // prettier-ignore
    children: l ? /* @__PURE__ */ u(N, { disabled: s, file: l, deleteFile: () => S(l) }) : /* @__PURE__ */ u(h, { ...f, ref: L, mapError: _, uploadFiles: g })
  });
});
export {
  j as FileInput,
  j as default
};
