import { j as O } from "../../node_modules/react/jsx-runtime.mjs";
import { memo as k, useRef as H, useState as D, useEffect as x } from "react";
import E from "./FuiCalendarItem.mjs";
import b from "../../node_modules/dayjs/plugin/isSameOrAfter.mjs";
import F from "../../node_modules/dayjs/plugin/isSameOrBefore.mjs";
import M from "../../node_modules/dayjs/plugin/utc.mjs";
import r from "../../node_modules/dayjs/dayjs.min.mjs";
import z from "./BitzFuiCalendarStore.mjs";
r.extend(M);
r.extend(F);
r.extend(b);
const y = 1440;
function w(i) {
  const a = [];
  return i.forEach((f) => {
    const l = r(f.startTime), c = r(f.endTime);
    let u = !1;
    for (let d = 0; d < a.length; d++) {
      const h = a[d];
      let g = !1;
      for (let e = 0; e < h.length; e++) {
        const n = h[e], t = r(n.startTime), s = r(n.endTime);
        if (l.isSameOrAfter(t) && l.isBefore(s) || c.isAfter(t) && c.isSameOrBefore(s) || t.isSameOrAfter(l) && t.isBefore(c) || s.isAfter(l) && s.isSameOrBefore(c)) {
          g = !0;
          break;
        }
      }
      if (!g) {
        h.push(f), u = !0;
        break;
      }
    }
    u || a.push([f]);
  }), a;
}
const I = (i) => {
  const { time: a } = i, {
    colHeight: f,
    setColHeight: l
  } = z((e) => e), c = H(null), u = 194.4, [d, h] = D([]);
  x(() => {
    var e, n;
    if ((e = i == null ? void 0 : i.list) != null && e.length) {
      let t = (n = i == null ? void 0 : i.list) == null ? void 0 : n.filter((o) => {
        let T = r(o.startTime), S = r(o.endTime);
        return T.isSame(a, "day") || S.isSame(a, "day");
      });
      const s = t == null ? void 0 : t.map((o) => ({
        ...o,
        startTime: r(o.startTime).utc(),
        endTime: r(o.endTime).utc()
      })), m = w(s);
      h(m);
    }
  }, [i == null ? void 0 : i.list, a]), x(() => {
    f || setTimeout(() => {
      var n;
      const e = ((n = c.current) == null ? void 0 : n.getBoundingClientRect().height) ?? 0;
      l(e);
    }, 0);
  }, [c.current]), x(() => {
  }, [f]);
  const g = (e, n, t, s) => {
    let m = r(e), o = r(n);
    const T = a.startOf("day");
    m.isBefore(T) && (m = T);
    const S = a.endOf("day");
    o.isAfter(S) && (o = S);
    const B = m.hour() * 60 + m.minute(), C = o.diff(m, "minute"), j = B / y * u, A = C / y * u, R = u / y * C, _ = (s - t - 1) / s * 100, $ = t / s * 100;
    return {
      right: `${_}%`,
      left: `${$}%`,
      top: `${j}rem`,
      height: `${A}rem`,
      maxHeight: `${R}rem`
    };
  };
  return /* @__PURE__ */ O.jsx("div", { className: "bitzFuiCalendarBody__content__row__list2", ref: c, children: d.map((e, n) => e.map((t, s) => {
    const { maxHeight: m, ...o } = g(
      t.startTime,
      t.endTime,
      n,
      d.length
    );
    return /* @__PURE__ */ O.jsx(
      E,
      {
        event: t,
        style: o,
        maxHeight: m
      },
      s
    );
  })) });
}, U = k(I);
export {
  U as default
};
