"use client";
import { jsx as a, jsxs as d } from "react/jsx-runtime";
import { forwardRef as g, useMemo as y, useCallback as f } from "react";
import { VariableSizeList as h } from "../../../../../../node_modules/react-window/dist/index.esm.js";
import { MinusSquareOutlined as E } from "../../../assets/icons/MinusSquareOutlined.js";
import { PlusSquareOutlined as b } from "../../../assets/icons/PlusSquareOutlined.js";
import { GanttConsts as o } from "../../../constants/GanttConsts.js";
const T = g(
  ({ height: c, data: l, setData: s, treeTitle: p = "Attività" }, m) => {
    const i = y(() => {
      const t = [];
      for (const e of l)
        Object.prototype.hasOwnProperty.call(e, "expanded") && !e.expanded && t.push(e.key);
      return l.filter((e) => !e.parentsKeys.some(
        (n) => t.includes(n)
      ));
    }, [l]), u = f(
      (t) => {
        const e = [...l], r = e.find((n) => n.key === t);
        r && Object.prototype.hasOwnProperty.call(r, "expanded") && (r.expanded = !r.expanded), s(e);
      },
      [l, s]
    );
    return /* @__PURE__ */ a(
      "div",
      {
        className: "gantt-tree-wrap bg-d-background",
        style: {
          width: o.TREE_WIDTH,
          marginTop: -o.HEADER_HEIGHT
        },
        children: /* @__PURE__ */ a(
          h,
          {
            ref: m,
            className: "gantt-tree-list bg-d-background",
            layout: "vertical",
            width: "100%",
            height: c,
            itemCount: i.length,
            itemSize: () => o.ROW_HEIGHT,
            itemData: i,
            innerElementType: ({ children: t, props: e }) => /* @__PURE__ */ d(
              "div",
              {
                style: { height: i.length * o.ROW_HEIGHT },
                ...e,
                children: [
                  /* @__PURE__ */ a(
                    "div",
                    {
                      className: "gantt-tree-title bg-d-background",
                      style: { height: o.HEADER_HEIGHT },
                      children: p
                    }
                  ),
                  /* @__PURE__ */ a("div", { className: "gantt-tree-inner-wrap", children: t })
                ]
              }
            ),
            children: ({ style: t, index: e, data: r }) => {
              const n = r[e];
              return /* @__PURE__ */ d(
                "button",
                {
                  className: "gantt-tree-list-item bg-d-background text-foreground",
                  style: {
                    ...t,
                    backgroundColor: e % 2 === 0 ? "var(--d-background)" : "var(--d-secondary)",
                    paddingLeft: o.LEAF_TITLE_PADDING_LEFT + n.level * o.LEAF_CHILDREN_PADDING_LEFT
                  },
                  onClick: () => u(n.key),
                  children: [
                    Object.prototype.hasOwnProperty.call(n, "expanded") ? n.expanded ? /* @__PURE__ */ a(E, { className: "gantt-tree-icon" }) : /* @__PURE__ */ a(b, { className: "gantt-tree-icon" }) : null,
                    /* @__PURE__ */ a("div", { children: r[e].title })
                  ]
                }
              );
            }
          }
        )
      }
    );
  }
);
T.displayName = "Tree";
export {
  T as default
};
