import { jsx as M } from "react/jsx-runtime";
import { a as h } from "./index.CfQlFjZU.js";
import { U } from "./Upload.X0oU32lw.js";
import { useState as b, useMemo as R } from "react";
import { g as j, a as v, b as E } from "./image.Cmad0xlQ.js";
const m = ["image/png", "image/jpeg", "image/webp"], H = ({
  imageFile: e,
  onImageChange: r,
  onCropComplete: p,
  uploading: l,
  maxSizeMB: o = 16,
  minWidth: a = 512,
  minHeight: t = 512,
  error: i
}) => {
  const [s, n] = b(), u = async (d) => {
    const f = j(d);
    if (!v(d, o)) {
      n(`Max image size ${o} MB`);
      return;
    }
    if (!E(d, m)) {
      n("File is invalid type, allowed types: png, jpeg, webp");
      return;
    }
    const { width: w, height: y } = await f;
    if (w < a || y < t) {
      n(
        `Image too small, recommended size is ${a} x ${t} px`
      );
      return;
    }
    r(d), n(void 0);
  }, g = () => {
    r(void 0);
  }, c = R(() => {
    if (e)
      return {
        name: e.name || "",
        src: URL.createObjectURL(e)
      };
  }, [e]);
  return {
    onMediaChange: u,
    onMediaRemove: g,
    onCropComplete: p,
    suggestedAllowedMediaTypes: m,
    uploadFile: c,
    uploading: !!l,
    uploadHelper: s || i || `Upload an image (max ${o} MB)`,
    uploadError: !!(i || s)
  };
}, T = ({
  onMediaChange: e,
  onMediaRemove: r,
  onCropComplete: p,
  suggestedAllowedMediaTypes: l,
  uploadFile: o,
  uploading: a,
  uploadHelper: t,
  uploadError: i
}) => /* @__PURE__ */ M(
  U,
  {
    allowCropping: !0,
    label: "Upload",
    helper: t,
    error: i,
    suggestedAllowedTypes: l,
    onFileSelect: (s) => e(s),
    onFileRemove: () => r(),
    file: o,
    uploading: a,
    onCropComplete: p
  }
), C = h(T, H);
export {
  C as H
};
