"use client";
import { jsx as i } from "react/jsx-runtime";
import p from "../../../../../_virtual/dayjs.min.js";
import z from "../../../../../_virtual/localizedFormat.js";
import { useMemo as a, useRef as H, useState as e } from "react";
import { GanttContext as M } from "./GanttContext.js";
import N from "../Chart/Chart.js";
import P from "../Controls/Controls.js";
import { GanttDimensions as c } from "../../enums/GanttDimensions.js";
import { GanttUnitOfTimes as m } from "../../enums/GanttUnitOfTimes.js";
import { getScaleDates as Y } from "../../utils/getScaleDates.js";
import { getInitialScrollOffset as A } from "../../utils/getInitialScrollOffset.js";
import { DragStepSizes as U } from "../../enums/DragStepSizes.js";
import { GanttConsts as _ } from "../../constants/GanttConsts.js";
import { GanttDimensionsSettings as s } from "../../constants/DimensionsSettings.js";
import { DragStepOptions as b } from "../../constants/DragStepOptions.js";
p.extend(z);
const l = ({
  children: S,
  draggable: d = !1,
  defaultDimension: t = c.HOUR,
  defaultDragStepSize: n = U.THIRTY_MIN,
  treeTitle: f
}) => {
  const r = a(() => {
    const o = t === c.DAY ? m.MONTH : m.DAY;
    return Y(void 0, void 0, o);
  }, [t]), x = a(() => A(t, r), [t, r]), I = H(null), [g, v] = e(p().unix()), [u, O] = e(r), [C, G] = e({
    stepWidth: s[t].stepWidth,
    secondsInPixel: s[t].secondsInPixel,
    scaleStepItems: _.HOURS_IN_DAY,
    initialScrollOffset: x,
    dimension: t,
    draggable: d,
    dragStepSize: n,
    gridSize: (() => {
      const o = b[n].seconds, D = s[t].secondsInPixel, T = o / D;
      return Math.max(T, 1);
    })()
  }), [R, h] = e({
    overscanStartIndex: 0,
    overscanStopIndex: 0,
    visibleStartIndex: 0,
    visibleStopIndex: 0
  });
  return /* @__PURE__ */ i(
    M.Provider,
    {
      value: {
        wrapRef: I,
        scaleDates: u,
        setScaleDates: O,
        settings: C,
        setSettings: G,
        scaleRenderState: R,
        setScaleRenderState: h,
        currentDate: g,
        setCurrentDate: v,
        treeTitle: f
      },
      children: /* @__PURE__ */ i("div", { className: "gantt-wrap", children: S })
    }
  );
};
l.Chart = N;
l.Controls = P;
export {
  l as default
};
