"use client";
import { jsx as l, Fragment as S } from "react/jsx-runtime";
import u from "../../../../../../../../_virtual/dayjs.min.js";
import { useMemo as f } from "react";
import { DataRepeatTypes as p } from "../../../../../enums/DataRepeatTimes.js";
import _ from "../BarItem/BarItem.js";
import { GanttConsts as c } from "../../../../../constants/GanttConsts.js";
const I = ({
  data: o,
  firstRenderedDate: t,
  lastRenderedDate: i,
  title: T,
  barKey: D,
  leftRender: h,
  onBarDoubleClick: N
}) => {
  const s = f(() => {
    if (!t)
      return null;
    const e = o.fromDate ? u(o.fromDate).unix() : t;
    return e > t ? e : t;
  }, [o.fromDate, t]), m = f(() => {
    if (!i)
      return null;
    const e = o.toDate ? u(o.toDate).unix() : i;
    return e < i ? e : i;
  }, [o.toDate, i]), n = f(() => o.toTime < o.fromTime ? o.toTime + c.SECONDS_IN_DAY - o.fromTime : o.toTime - o.fromTime, [o.fromTime, o.toTime]), x = f(() => {
    if (!s || !m || !n)
      return [];
    const e = [];
    let r = u.unix(s).startOf("day").add(o.fromTime, "seconds").unix();
    switch (o.repeatType) {
      case p.DAY: {
        for (; r <= m; )
          e.push({
            startDate: r,
            endDate: r + n
          }), r = r + c.SECONDS_IN_DAY;
        break;
      }
      case p.WEEK:
        for (; r <= m; )
          o.weekdays?.includes(+u.unix(r).format("d")) && e.push({
            startDate: r,
            endDate: r + n
          }), r = r + c.SECONDS_IN_DAY;
        break;
      case p.MONTH:
        for (; r <= m; )
          o.monthdays?.includes(+u.unix(r).format("D")) && e.push({
            startDate: r,
            endDate: r + n
          }), r = r + c.SECONDS_IN_DAY;
        break;
    }
    return e;
  }, [o, n, s, m]);
  return !s || !m ? null : /* @__PURE__ */ l(S, { children: x.map(({ startDate: e, endDate: r }) => /* @__PURE__ */ l(
    _,
    {
      title: T,
      barKey: D,
      startDate: e,
      endDate: r,
      repetead: !0,
      leftRender: h,
      onBarDoubleClick: N
    },
    D + e
  )) });
};
export {
  I as default
};
