import { jsxs as n, jsx as o } from "react/jsx-runtime";
import { useId as v, useState as g } from "react";
import { Classes as x } from "../../constants/selectors.js";
import { Folder2OpenIcon as h, Folder2Icon as I } from "../../icons/index.js";
import { cn as b } from "../../utils/cn.js";
import { TreeLevelProvider as k } from "./context.js";
import { useTreeLevel as F } from "./use-tree-level.js";
import { calculatePaddingLeft as N } from "./utils.js";
const P = ({
  name: a,
  defaultOpen: c = !1,
  children: l,
  openable: p = !0
}) => {
  const d = v(), i = `tree-folder-${d}`, s = `tree-group-${d}`, e = p && !!l, { level: t } = F(), [r, m] = g(e && c), f = e && r ? h : I;
  return /* @__PURE__ */ n(
    "div",
    {
      "data-component-part": "tree-folder",
      role: "none",
      style: { "--padding-left": N(t) },
      children: [
        /* @__PURE__ */ n(
          "div",
          {
            "aria-expanded": e ? r : void 0,
            "aria-level": t,
            "aria-owns": e && r ? s : void 0,
            "aria-selected": !1,
            className: b(
              "flex items-center gap-1.5 rounded-lg py-1 pr-1.5 pl-[calc(var(--padding-left)*1px)] text-stone-700 -outline-offset-1 hover:bg-stone-100 dark:text-stone-400 dark:hover:bg-stone-900",
              e ? "cursor-pointer" : "cursor-default",
              x.TreeFolder
            ),
            id: i,
            onClick: e ? () => m((u) => !u) : void 0,
            role: "treeitem",
            tabIndex: -1,
            children: [
              /* @__PURE__ */ o(
                f,
                {
                  "aria-hidden": "true",
                  className: "size-4 shrink-0 select-none",
                  "data-component-part": e && r ? "tree-folder-icon-open" : "tree-folder-icon-closed"
                }
              ),
              /* @__PURE__ */ o(
                "span",
                {
                  className: "truncate font-medium text-sm leading-5 -tracking-[0.1px]",
                  "data-component-part": "tree-folder-title",
                  title: a,
                  children: a
                }
              )
            ]
          }
        ),
        e && r && // biome-ignore lint/a11y/useSemanticElements: TODO
        /* @__PURE__ */ n(
          "div",
          {
            className: "relative",
            "data-component-part": "tree-folder-children-wrapper",
            id: s,
            role: "group",
            children: [
              /* @__PURE__ */ o(
                "div",
                {
                  "aria-hidden": "true",
                  className: "absolute left-[calc((var(--padding-left)+8)*1px)] z-10 h-full w-px select-none bg-stone-200 dark:bg-stone-800",
                  "data-component-part": "tree-folder-children-line"
                }
              ),
              /* @__PURE__ */ o(k, { level: t + 1, parentId: i, children: l })
            ]
          }
        )
      ]
    }
  );
};
export {
  P as TreeFolder
};
