"use client";
import { jsx as n, jsxs as b, Fragment as G } from "react/jsx-runtime";
import L from "../../../../../_virtual/index8.js";
import _ from "../../../../../_virtual/debounce3.js";
import { useContext as j, useRef as l, useState as o, useCallback as M, useMemo as N, useEffect as a } from "react";
import { GanttContext as O } from "../Gantt/GanttContext.js";
import { transformData as k } from "../../utils/transformData.js";
import y from "./Scale/Scale.js";
import A from "./Tree/Tree.js";
import B from "./Bars/Bars.js";
import { GanttConsts as f } from "../../constants/GanttConsts.js";
import { GanttDimensionsSettings as F } from "../../constants/DimensionsSettings.js";
const Z = ({
  data: u,
  className: E,
  onBarDoubleClick: H,
  onBarChange: R
}) => {
  const { settings: e, scaleDates: s, wrapRef: t, setCurrentDate: m, treeTitle: S } = j(O), d = l(null), p = l(null), h = l(null), [T, c] = o(
    []
  ), [i, x] = o(!0), [g, W] = o(0), [D, w] = o(0), C = M(() => {
    const r = Math.round(
      ((t?.current?.scrollLeft || 0) + f.TREE_WIDTH) * F[e.dimension].secondsInPixel
    );
    m(s[0] + r);
  }, [s, m, e.dimension, t]), I = N(() => _(C, 100), [C]);
  return a(() => {
    t?.current?.clientWidth && t?.current?.clientHeight && (W(t.current.clientWidth - f.TREE_WIDTH), w(t.current.clientHeight - f.HEADER_HEIGHT), x(!1));
  }, [t]), a(() => {
    !i && t.current && (t.current.scrollLeft = e.initialScrollOffset);
  }, [i, t, e.initialScrollOffset]), a(() => {
    c(k(u));
  }, [u]), /* @__PURE__ */ n(
    "div",
    {
      className: L("gantt-chart-wrap", E),
      ref: t,
      onScroll: (r) => {
        h.current?.scrollTo(r.currentTarget.scrollTop), p.current?.scrollTo(r.currentTarget.scrollTop), d.current?.scrollTo(r.currentTarget.scrollLeft), I();
      },
      children: i ? /* @__PURE__ */ n(
        "div",
        {
          style: {
            width: e.scaleStepItems * e.stepWidth * s.length
          }
        }
      ) : /* @__PURE__ */ b(G, { children: [
        /* @__PURE__ */ n(y, { width: g, wrapRef: t, ref: d }),
        /* @__PURE__ */ n(
          A,
          {
            height: D,
            data: T,
            setData: c,
            ref: p,
            treeTitle: S
          }
        ),
        /* @__PURE__ */ n(
          B,
          {
            ref: h,
            data: T,
            setData: c,
            width: g,
            height: D,
            onBarDoubleClick: H,
            onBarChange: R
          }
        )
      ] })
    }
  );
};
export {
  Z as default
};
