import { u, a as d, r as p } from "./xlsx-Byegf6ga.js";
import "./dayjs.min-D5mIeZ1x.js";
import "./app-Bpb4394e.js";
function* x(e) {
  const [t, o] = e.split(":"), n = /\d+/, r = n.exec(t), a = n.exec(o);
  if (!r || !a)
    throw new Error(`Cannot parse row range for range: ${e}`);
  const c = Number(r[0]), i = Number(a[0]);
  for (let s = c; s <= i; s++)
    yield s;
}
function* M(e) {
  const [t, o] = e.split(":"), n = /[^\d]+/, r = n.exec(t), a = n.exec(o);
  if (!r || !a)
    throw new Error(`Cannot parse row range for range: ${e}`);
  let c = 0, i = "A";
  for (yield i; i !== a[0]; ) {
    c++;
    const s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    let l = c, h = !1, f = "";
    do {
      const w = l % s.length;
      l = Math.floor(l / s.length), f += s.charAt(w), h = l > 0, l -= 1;
    } while (h);
    i = f.split("").reverse().join(""), yield i;
  }
}
function _(e) {
  var n;
  const t = [], o = e["!ref"];
  if (!o) return t;
  for (const r of x(o)) {
    const a = [];
    for (const c of M(o))
      a.push(((n = e[`${c}${r}`]) == null ? void 0 : n.w) ?? "");
    t.push(a);
  }
  return t;
}
function m(e) {
  return e.replace(/[\\/?*\[\]:]/g, " ").replace(/\s+/g, " ").slice(0, 31).trim() || "Sheet1";
}
function g(e, t) {
  const o = m(e);
  if (!t.has(o))
    return t.add(o), o;
  let n = 1;
  for (; n < Number.MAX_SAFE_INTEGER; ) {
    const r = ` (${n})`, a = o.slice(0, Math.max(31 - r.length, 0)).trim(), c = a ? `${a}${r}` : r.trim();
    if (!t.has(c))
      return t.add(c), c;
    n += 1;
  }
  throw new Error("Exhausted all possible sheet names");
}
function b(e, t, o = "Sheet1") {
  const n = u.aoa_to_sheet([t, ...e]), r = e.reduce((i, s) => Math.max(i, s.length), 0), a = Array.from({ length: r }).map((i, s) => {
    const l = e.map((h) => `${h[s]}`).reduce((h, f) => Math.max(h, f.length + 3), 0);
    return {
      wch: Math.max(l, 5)
    };
  });
  n["!cols"] = a;
  const c = u.book_new();
  return u.book_append_sheet(c, n, m(o)), c;
}
function E(e, t) {
  const o = u.aoa_to_sheet([t, ...e]), n = e.reduce((a, c) => Math.max(a, c.length), 0), r = Array.from({ length: n }).map((a, c) => {
    const i = e.map((s) => `${s[c]}`).reduce((s, l) => Math.max(s, l.length + 3), 0);
    return {
      wch: Math.max(i, 5)
    };
  });
  return o["!cols"] = r, o;
}
function N(e, t) {
  const o = u.book_new(), n = /* @__PURE__ */ new Set();
  t ?? (t = Object.keys(e));
  for (const r of t)
    u.book_append_sheet(
      o,
      e[r],
      g(String(r), n)
    );
  return o;
}
function A(e, t) {
  d(e, t, { compression: !0 });
}
async function $(e) {
  return p(await e.arrayBuffer());
}
export {
  N as a,
  b,
  A as d,
  $ as r,
  _ as s,
  E as t,
  g as u
};
