import p from "../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
function x(e) {
  return Object.assign(Object.assign({}, e), {
    lastModified: e.lastModified,
    lastModifiedDate: e.lastModifiedDate,
    name: e.name,
    size: e.size,
    type: e.type,
    uid: e.uid,
    percent: 0,
    originFileObj: e
  });
}
function y(e, n) {
  const t = p(n), r = t.findIndex((s) => {
    let {
      uid: i
    } = s;
    return i === e.uid;
  });
  return r === -1 ? t.push(e) : t[r] = e, t;
}
function w(e, n) {
  const t = e.uid !== void 0 ? "uid" : "name";
  return n.filter((r) => r[t] === e[t])[0];
}
function b(e, n) {
  const t = e.uid !== void 0 ? "uid" : "name", r = n.filter((s) => s[t] !== e[t]);
  return r.length === n.length ? null : r;
}
const f = function() {
  const n = (arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "").split("/"), r = n[n.length - 1].split(/#|\?/)[0];
  return (/\.[^./\\]*$/.exec(r) || [""])[0];
}, l = (e) => e.indexOf("image/") === 0, U = (e) => {
  if (e.type && !e.thumbUrl)
    return l(e.type);
  const n = e.thumbUrl || e.url || "", t = f(n);
  return /^data:image\//.test(n) || /(webp|svg|png|gif|jpg|jpeg|jfif|bmp|dpg|ico|heic|heif)$/i.test(t) ? !0 : !(/^data:/.test(n) || t);
}, a = 200;
function R(e) {
  return new Promise((n) => {
    if (!e.type || !l(e.type)) {
      n("");
      return;
    }
    const t = document.createElement("canvas");
    t.width = a, t.height = a, t.style.cssText = `position: fixed; left: 0; top: 0; width: ${a}px; height: ${a}px; z-index: 9999; display: none;`, document.body.appendChild(t);
    const r = t.getContext("2d"), s = new Image();
    if (s.onload = () => {
      const {
        width: i,
        height: u
      } = s;
      let o = a, d = a, c = 0, m = 0;
      i > u ? (d = u * (a / i), m = -(d - o) / 2) : (o = i * (a / u), c = -(o - d) / 2), r.drawImage(s, c, m, o, d);
      const g = t.toDataURL();
      document.body.removeChild(t), window.URL.revokeObjectURL(s.src), n(g);
    }, s.crossOrigin = "anonymous", e.type.startsWith("image/svg+xml")) {
      const i = new FileReader();
      i.onload = () => {
        i.result && (s.src = i.result);
      }, i.readAsDataURL(e);
    } else if (e.type.startsWith("image/gif")) {
      const i = new FileReader();
      i.onload = () => {
        i.result && n(i.result);
      }, i.readAsDataURL(e);
    } else
      s.src = window.URL.createObjectURL(e);
  });
}
export {
  x as file2Obj,
  w as getFileItem,
  U as isImageUrl,
  R as previewImage,
  b as removeFileItem,
  y as updateFileList
};
