"use client";
import { jsxs as d, jsx as n } from "react/jsx-runtime";
import y from "../../../../../_virtual/dayjs.min.js";
import { useContext as G, useState as h, useMemo as f, useCallback as a } from "react";
import { Button as g } from "../../../button.js";
import { Select as S, SelectTrigger as b, SelectValue as x, SelectContent as v, SelectItem as C } from "../../../select.js";
import { cn as P } from "../../../../../lib/utils.js";
import { GanttContext as B } from "../Gantt/GanttContext.js";
import { useGanttCalculate as L } from "../../hooks/useGanttCalculate.js";
import M from "../../../../../node_modules/lucide-react/dist/esm/icons/chevron-left.js";
import R from "../../../../../node_modules/lucide-react/dist/esm/icons/chevron-right.js";
import { GanttDimensionsSettings as l } from "../../constants/DimensionsSettings.js";
import { DragStepOptions as u } from "../../constants/DragStepOptions.js";
const Y = ({ className: D }) => {
  const { calculate: s } = L(), { settings: r, setSettings: p, currentDate: j } = G(B), [z, c] = h(r.dimension), [t, m] = h(
    Object.keys(l).findIndex(
      (e) => e === r.dimension
    )
  ), o = f(() => Object.keys(l).map((e, i) => ({
    label: l[e].label,
    value: e,
    index: i
  })), []), N = a(
    (e) => {
      const i = o.findIndex((V) => V.value === e);
      c(e), m(i), s(e);
    },
    [s, o]
  ), O = a(() => {
    if (t < o.length - 1) {
      const e = Object.keys(l)[t + 1];
      c(e), m(t + 1), s(e);
    }
  }, [s, o.length, t]), k = a(() => {
    if (t > 0) {
      const e = Object.keys(l)[t - 1];
      c(e), m(t - 1), s(e);
    }
  }, [s, t]), I = f(() => Object.keys(u).map((e) => ({
    label: u[e].label,
    value: e
  })), []), w = a(
    (e) => {
      p(() => {
        const i = { ...r };
        return i.dragStepSize = e, i.gridSize = u[e].seconds / l[i.dimension].secondsInPixel, i;
      });
    },
    [p, r]
  );
  return /* @__PURE__ */ d(
    "div",
    {
      className: P(
        "border-d-border flex items-center gap-2 border-b p-4",
        D
      ),
      children: [
        /* @__PURE__ */ n(
          g,
          {
            variant: "outline",
            size: "icon",
            onClick: k,
            disabled: t <= 0,
            children: /* @__PURE__ */ n(M, { className: "h-4 w-4" })
          }
        ),
        /* @__PURE__ */ d(S, { value: z, onValueChange: N, children: [
          /* @__PURE__ */ n(b, { className: "w-[180px]", children: /* @__PURE__ */ n(x, { placeholder: "Seleziona dimensione" }) }),
          /* @__PURE__ */ n(v, { className: "z-100", children: o.map((e) => /* @__PURE__ */ n(C, { value: e.value, children: e.label }, e.value)) })
        ] }),
        /* @__PURE__ */ n(
          g,
          {
            variant: "outline",
            size: "icon",
            onClick: O,
            disabled: t >= o.length - 1,
            children: /* @__PURE__ */ n(R, { className: "h-4 w-4" })
          }
        ),
        /* @__PURE__ */ n("div", { className: "px-4 text-sm font-medium", children: y.unix(j).format("ddd, ll") }),
        /* @__PURE__ */ d(S, { value: r.dragStepSize, onValueChange: w, children: [
          /* @__PURE__ */ n(b, { className: "w-[180px]", children: /* @__PURE__ */ n(x, { placeholder: "Seleziona step" }) }),
          /* @__PURE__ */ n(v, { children: I.map((e) => /* @__PURE__ */ n(C, { value: e.value, children: e.label }, e.value)) })
        ] })
      ]
    }
  );
};
export {
  Y as default
};
