import { c as P, d as B, e as Y, g as F, h as T, i as N, j as $, f as l, k as R, l as K, m as z, n as H, o as L, p as j, q as Q, r as C, t as U, u as G, v as X } from "../lite.js";
import { E as Z, V as J, B as tt } from "./constants.js";
import { R as et } from "./enums.js";
const dt = (t) => typeof t == "object" && t !== null && Object.prototype.toString.call(t) === "[object Object]", ft = (t) => Array.isArray(t), ut = (t, e = () => !0) => {
  const r = {};
  for (const s in t)
    if (Object.prototype.hasOwnProperty.call(t, s)) {
      const n = t[s];
      e(n, s) && (r[s] = n);
    }
  return r;
}, lt = (t) => t != null && t !== !1 && !(typeof t == "object" && Object.keys(t).length === 0), yt = (t, e = !1) => t != null && (!e || t !== ""), ht = (...t) => {
  const e = P(...t);
  if (!e)
    return;
  const r = new Set(e.split(/\s+/).filter(Boolean));
  if (r.size > 0)
    return [...r].join(" ");
}, pt = (t, ...e) => P(...e) || void 0, mt = (t, e) => {
  if (!t || Object.keys(t).length === 0)
    return e && Object.keys(e).length > 0 ? e : {};
  const r = {};
  for (const s in t) {
    const n = (e == null ? void 0 : e[s]) || "", o = t[s];
    if (typeof o == "string")
      r[s] = o;
    else if (typeof o == "function") {
      const a = o(n);
      r[s] = a !== void 0 ? a : n;
    } else
      r[s] = n;
  }
  if (e)
    for (const s in e)
      s in r || (r[s] = e[s] || "");
  return r;
}, gt = (t = 6) => {
  const e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  return Array.from({ length: t }, () => e.charAt(Math.floor(Math.random() * e.length))).join("");
}, Mt = (t = {}, e = {}) => ({ ...t, ...e }), Dt = (t, e) => {
  const r = t.reduce(
    (s, n, o) => {
      const a = n[e], c = a == null || a === "" ? Z : a.toString();
      return s[c] || (s[c] = []), s[c].push({ index: o, item: n }), s;
    },
    {}
  );
  return {
    groupedData: r,
    keys: Object.keys(r)
  };
}, bt = (t, e, r = !1) => {
  const s = {};
  if (!t)
    return s;
  if (r) {
    const n = Object.keys(t);
    for (const o of n)
      e.includes(o) || (s[o] = t[o]);
  } else
    for (const n of e)
      n in t && (s[n] = t[n]);
  return s;
}, rt = (...t) => {
  for (const [e, r] of t)
    if (r)
      return e;
  return !1;
}, At = (t, e = !1) => {
  const r = rt(...t);
  return r !== !1 ? r : e;
}, st = (t) => t.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), kt = (t, ...e) => {
  const r = B(e);
  if (typeof t == "function")
    for (const [s, n] of Object.entries(r)) {
      const o = t(n, s, r);
      if (o && typeof o == "object") {
        const { tKey: a, tValue: c } = o, i = c ?? n;
        a ? (delete r[s], r[a] = i) : r[s] = i;
      }
    }
  return r;
}, St = (t) => {
  const e = tt;
  if (t.startsWith(e)) {
    const r = t.slice(e.length), s = st(r);
    return J + s;
  }
  return t;
}, vt = (t) => typeof t == "boolean" ? t && "rounded" : `rounded-${et[t]}`, wt = (t, e, r) => {
  r = r % e;
  const s = (t + r) % e;
  return s < 0 ? s + e : s;
}, Et = (t, e, r) => {
  const s = (e - t + r) % r === 1, n = (t - e + r) % r === 1;
  return { isNext: s, isPrev: n };
}, Ot = (t) => t.charAt(0).toUpperCase() + t.slice(1), _t = (t) => {
  let e = window.innerWidth - document.body.clientWidth + "";
  if (e === "0") {
    const r = document.body.dataset.lastScrollbarWidth;
    r && (e = r);
  } else
    document.body.dataset.lastScrollbarWidth = e;
  return t ? e + t : e;
}, Tt = (t, e, r = 4, s = !1) => {
  if (typeof t != "number" || typeof e != "number" || e === 0)
    return [];
  if (e <= r + 2)
    return Array.from({ length: e }, (i, d) => d + 1);
  const n = [1], o = Math.floor(r / 2);
  let a = Math.max(2, t - o), c = Math.min(e - 1, t + o);
  return c - a + 1 < r && (a === 2 ? c = Math.min(e - 1, a + r - 1) : c === e - 1 && (a = Math.max(2, c - r + 1))), (s || a > 2) && n.push("<"), n.push(...Array.from({ length: c - a + 1 }, (i, d) => a + d)), (s || c < e - 1) && n.push(">"), n.push(e), n;
}, jt = (t, e = null, r = "") => {
  const s = /* @__PURE__ */ new Map(), n = (o, a, c) => {
    o.forEach((i) => {
      const d = c ? `${c}-${i.id}` : `${i.id}`;
      s.set(d, {
        ...i,
        _metadata: {
          id: i.id,
          path: d,
          ...a !== null ? { parentId: a } : {}
        }
      }), i.children && i.children.length > 0 && n(i.children, i.id, d);
    });
  };
  return n(t, e, r), s;
}, nt = (t, e, r, s) => {
  const n = e.get(r);
  if (!n)
    return t;
  const o = n._metadata.path.split("-"), a = (c, i) => c.map((d) => {
    if (d.id === i[0]) {
      if (i.length === 1)
        return s(d);
      if (d.children) {
        const f = a(d.children, i.slice(1));
        if (f !== d.children)
          return { ...d, children: f };
      }
    }
    return d;
  });
  return a(t, o);
}, Vt = (t, e, r, s) => r.reduce((n, o) => nt(n, e, o, s), t), Wt = (t, e) => {
  const r = e.get(t);
  if (!r)
    return [];
  const s = [], n = r._metadata.path.split("-");
  for (let o = n.length - 2; o >= 0; o--) {
    const a = n.slice(0, o + 1).join("-");
    e.has(a) && !e.get(a).disabled && s.push(a);
  }
  return s;
}, It = (t, e) => {
  const r = e.get(t);
  if (!r)
    return [];
  const s = [], n = r._metadata.path;
  for (const [o, { _metadata: a }] of e.entries())
    o !== t && a.path.startsWith(n) && !e.get(o).disabled && s.push(o);
  return s;
}, Nt = (t) => {
  function e(r) {
    if (!r.children || r.children.length === 0) {
      r.indeterminate = !1;
      return;
    }
    let s = !1, n = !1;
    r.children.forEach((o) => {
      e(o), o.checked && (s = !0), (!o.checked || o.indeterminate) && (n = !0);
    }), r.indeterminate = s && n;
  }
  t.forEach(e);
}, Pt = (t, e) => {
  const r = e, s = (i, d) => {
    for (const f of i) {
      if (f.id === d)
        return [f];
      if (f.children) {
        const b = s(f.children, d);
        if (b)
          return [f, ...b];
      }
    }
    return null;
  }, n = (i, d) => {
    i.children && i.children.forEach((f) => {
      f.disabled || (f.checked = d, f.indeterminate = !1, n(f, d));
    });
  }, o = (i) => {
    for (let d = i.length - 2; d >= 0; d--) {
      const f = i[d], b = f.children ?? [], A = b.every((y) => !y.disabled && y.checked), E = b.some((y) => !y.disabled && (y.checked || y.indeterminate));
      f.checked = A, f.indeterminate = !A && E;
    }
  }, a = s(t, r.id);
  if (!a)
    return;
  const c = a[a.length - 1];
  c.disabled || (c.checked = r.checked, c.indeterminate = !1, n(c, c.checked)), o(a);
}, Yt = (t, e, r = [], s = 6, n = 1, o = [], a = null, c = void 0, i = !1, d = void 0) => {
  const f = Y(new Date(t, e)), b = F(f);
  let A = T(f, { weekStartsOn: n }), E = N(b, { weekStartsOn: n });
  if (s) {
    const u = s * 7;
    A = T(f, { weekStartsOn: n }), E = $(A, u - 1);
  }
  const y = Array.isArray(a) ? a : a ? [a] : [], q = new Set(y.map((u) => l(u, "yyyy-MM-dd")));
  let O = -1, V = !1;
  const S = R({ end: E, start: A }).map((u, m) => {
    const p = l(u, "yyyy-MM-dd"), h = r.filter(
      (k) => k.startTime ? l(new Date(k.startTime), "yyyy-MM-dd") === p : !1
    ), g = K(u), M = q.has(p);
    let D = g;
    return g && (O = m), M && (D = !0, O !== -1 && (V = !0)), {
      active: D,
      date: u,
      events: h,
      isCurrentMonth: z(u, f),
      isSelected: M,
      isToday: g
    };
  });
  V && O !== -1 && (S[O].active = !1), i && y.length > 0 && y.forEach((u) => {
    const m = T(u, { weekStartsOn: n }), p = N(u, { weekStartsOn: n });
    S.forEach((h) => {
      H(h.date, { end: p, start: m }) && (h.active = !0);
    });
  });
  const W = o.length > 0 ? o : Array.from(
    { length: 7 },
    (u, m) => l(new Date(1970, 0, m + 4), "EEEEE", {
      locale: c
    })
  ), I = W.slice(n).concat(W.slice(0, n));
  let v;
  if (d === "month") {
    const u = Array.from({ length: 12 }, (m, p) => {
      const h = new Date(t, p), g = l(h, "LL", { locale: c });
      return {
        active: y.some((D) => D.getMonth() === p),
        date: h,
        type: "month",
        value: g
      };
    });
    v = _(u, 3, 4);
  } else if (d === "quarter") {
    const u = Array.from({ length: 4 }, (m, p) => {
      const h = new Date(t, p * 3, 1), g = l(h, "QQ", { locale: c }), M = p * 3, D = M + 2;
      return {
        active: y.some(
          (w) => w.getMonth() >= M && w.getMonth() <= D
        ),
        date: h,
        type: "quarter",
        value: g
      };
    });
    v = _(u, 1, 4);
  } else if (d === "year") {
    const h = Array.from({ length: 13 }, (g, M) => {
      const D = M - 6, k = L(new Date(t, 0), D), w = l(k, "yyyy", { locale: c });
      return {
        active: y.some(
          (x) => x.getFullYear() === parseInt(w, 10)
        ),
        date: k,
        type: "year",
        value: w
      };
    });
    v = _(h, 3, 4);
  } else
    v = [
      I.map((u) => ({
        type: "header",
        value: u
      })),
      ..._(S, s || S.length / 7, 7)
    ];
  return {
    days: S,
    month: e,
    rows: v,
    weekHeader: I,
    year: t
  };
}, Ct = (t, e) => {
  const r = t.date, s = (n) => ({
    ...n,
    active: C(n.date, r)
  });
  return {
    ...e,
    days: e.days.map(s),
    rows: e.rows.map((n, o) => o === 0 ? n : n.map(s))
  };
}, qt = (t, e) => {
  const r = t.date, s = e.rows.findIndex(
    (n, o) => o !== 0 && n.some((a) => C(a.date, r))
  );
  return {
    ...e,
    rows: e.rows.map(
      (n, o) => o === 0 ? n : n.map((a) => ({
        ...a,
        active: o === s
      }))
    )
  };
}, xt = (t, e, r, s) => {
  const n = [...s.rows], o = [...n[e]];
  return o[r] = t, n[e] = o, {
    ...s,
    rows: n
  };
}, _ = (t, e, r, s) => {
  const n = [], o = [...t];
  for (let a = 0; a < e; a++)
    n.push(o.slice(a * r, (a + 1) * r));
  return n;
}, Bt = (t, e) => {
  const s = ((a) => a ? (Array.isArray(a) ? a : [a]).map((i) => typeof i == "string" ? j(i) : new Date(i)).filter(U) : [])(t);
  if (s.length === 0)
    return null;
  const n = (a) => {
    switch (e) {
      case "date":
        return { computedDate: a, formattedValue: l(a, "yyyy-MM-dd") };
      case "datetime":
        return { computedDate: a, formattedValue: l(a, "yyyy-MM-dd HH:mm:ss") };
      case "month": {
        const c = Y(a);
        return { computedDate: c, formattedValue: l(c, "yyyy-MM") };
      }
      case "quarter": {
        const c = X(a);
        return {
          computedDate: c,
          formattedValue: `${l(c, "yyyy")} Q${Math.ceil((c.getMonth() + 1) / 3)}`
        };
      }
      case "time":
        return { computedDate: a, formattedValue: l(a, "HH:mm:ss") };
      case "week": {
        const c = T(a, { weekStartsOn: 1 }), i = new Date(c.getTime() + 6 * 24 * 60 * 60 * 1e3);
        return {
          computedDate: c,
          formattedValue: `${l(c, "yyyy-MM-dd")} ~ ${l(i, "yyyy-MM-dd")}`
        };
      }
      case "year": {
        const c = G(a);
        return { computedDate: c, formattedValue: l(c, "yyyy") };
      }
      default:
        return { computedDate: a, formattedValue: "" };
    }
  }, o = s.map(n);
  return {
    computedDate: o.map((a) => a.computedDate),
    formattedValue: o.map((a) => a.formattedValue)
  };
}, Ft = (t, e) => {
  const r = typeof t == "string" ? j(t) : t, s = typeof e == "string" ? j(e) : e;
  return Q(r, s) ? [s, r] : [r, s];
};
export {
  Dt as A,
  dt as B,
  jt as C,
  Pt as D,
  nt as E,
  Vt as F,
  Wt as G,
  It as H,
  Nt as I,
  St as a,
  pt as b,
  ht as c,
  Et as d,
  wt as e,
  rt as f,
  Yt as g,
  Ot as h,
  Bt as i,
  xt as j,
  qt as k,
  Ft as l,
  Mt as m,
  gt as n,
  At as o,
  mt as p,
  ft as q,
  vt as r,
  kt as s,
  ut as t,
  Ct as u,
  lt as v,
  _t as w,
  Tt as x,
  bt as y,
  yt as z
};
//# sourceMappingURL=tools.js.map
