import { B as p } from "./app-Bpb4394e.js";
function l(s) {
  return Math.floor(s.getTime() / 1e3) * 1e3;
}
function u(s) {
  const c = [
    "Jan",
    "Feb",
    "Mar",
    "Apr",
    "May",
    "Jun",
    "Jul",
    "Aug",
    "Sep",
    "Oct",
    "Nov",
    "Dec"
  ], d = s.getFullYear(), r = c[s.getMonth()], o = s.getDate();
  let n = s.getHours();
  const i = s.getMinutes().toString().padStart(2, "0"), e = s.getSeconds().toString().padStart(2, "0"), t = n >= 12 ? "PM" : "AM";
  return n = n % 12, n = n || 12, `${d} ${r} ${o} ${n}:${i}:${e} ${t}`;
}
function y(s, c = []) {
  const d = s.map((e) => {
    const t = p(e._id), a = new Date(t);
    return {
      label: "",
      // Will be set after grouping
      value: e._id,
      type: "closing",
      date: a
    };
  }), r = c.map((e) => {
    const t = p(e._id), a = new Date(t);
    return {
      label: "",
      // Will be set after grouping
      value: e._id,
      type: "snapshot",
      date: a
    };
  }), o = [...d, ...r].sort(
    (e, t) => t.date.getTime() - e.date.getTime()
  ), n = /* @__PURE__ */ new Map();
  for (const e of o) {
    const t = l(e.date);
    n.has(t) || n.set(t, []), n.get(t).push(e);
  }
  const i = c.length > 0;
  for (const [, e] of n)
    if (e.length > 1)
      e.sort((t, a) => t.date.getTime() - a.date.getTime()), e.forEach((t, a) => {
        const g = i ? t.type === "closing" ? " (Closing)" : " (Snapshot)" : "";
        t.label = `${u(t.date)}${g} (Rev ${a + 1})`;
      });
    else {
      const t = e[0], a = i ? t.type === "closing" ? " (Closing)" : " (Snapshot)" : "";
      t.label = `${u(t.date)}${a}`;
    }
  return o.sort((e, t) => {
    const a = l(e.date), g = l(t.date);
    return a !== g ? g - a : t.date.getTime() - e.date.getTime();
  });
}
function f(s) {
  const c = s.getFullYear(), d = (s.getMonth() + 1).toString().padStart(2, "0"), r = s.getDate().toString().padStart(2, "0");
  return `${c}${d}${r}`;
}
function S(s) {
  const c = /* @__PURE__ */ new Map(), d = s.filter((o) => !!o.closingId).map((o) => {
    try {
      const n = p(o.closingId);
      return {
        closingId: o.closingId,
        closingDate: new Date(n),
        draftCreatedAt: o.draftCreatedAt
      };
    } catch {
      return null;
    }
  }).filter((o) => o !== null), r = /* @__PURE__ */ new Map();
  for (const o of d) {
    const n = f(o.closingDate);
    r.has(n) || r.set(n, []), r.get(n).push(o);
  }
  for (const [o, n] of r)
    n.sort((i, e) => i.draftCreatedAt.getTime() - e.draftCreatedAt.getTime()), n.forEach((i, e) => {
      const t = (e + 1).toString().padStart(4, "0");
      c.set(i.closingId, `${o}-${t}`);
    });
  return c;
}
export {
  S as f,
  y as g
};
