import { CONTENY_TYPE_APPLICATION_PDF as l, CONTENT_TYPE_IMAGE_PNG as d, CONTENT_TYPE_IMAGE_JPG as f } from "./index-Document.types.js";
import p from "./index-jszip.min.js";
const b = async (r, i, n) => {
  const a = await fetch(r);
  let o;
  if (n) {
    const c = await a.arrayBuffer();
    o = new Blob([c], {
      type: n
    });
  } else
    o = await a.blob();
  const t = URL.createObjectURL(o), e = document.createElement("a");
  e.href = t, e.style.display = "none", e.download = i, document.body.appendChild(e), e.click(), setTimeout(() => {
    document.body.removeChild(e);
  }, 0);
}, u = async (r, i) => {
  const n = new p();
  for (const e of r) {
    const s = await (await fetch(e.src)).arrayBuffer();
    n.file(e.name, s);
  }
  const a = await n.generateAsync({
    type: "blob"
  }), o = URL.createObjectURL(a), t = document.createElement("a");
  t.href = o, t.style.display = "none", t.download = i, document.body.appendChild(t), t.click(), setTimeout(() => {
    document.body.removeChild(t), URL.revokeObjectURL(o);
  }, 0);
};
async function w(r) {
  const n = await (await fetch(r, {
    method: "GET",
    headers: {
      Range: "bytes=0-20"
    }
  })).arrayBuffer(), a = new Uint8Array(n), o = Array.from(a).map((e) => e.toString(16).padStart(2, "0")).join(" "), t = {
    "ff d8 ff": f,
    "89 50 4e 47 0d 0a 1a 0a": d,
    "25 50 44 46": l
    // PDF
  };
  for (const e in t)
    if (o.startsWith(e))
      return t[e];
  return "unknown";
}
export {
  b as downloadFile,
  u as downloadZipFile,
  w as inspectFileMimeTypeFromURL
};
