"use client";

import { TreeView as ChakraTreeView } from "@chakra-ui/react";
import * as React from "react";

export const TreeViewRoot = React.forwardRef<
  HTMLDivElement,
  ChakraTreeView.RootProps
>(function TreeViewRoot(props, ref) {
  return <ChakraTreeView.Root {...props} ref={ref} />;
});

interface TreeViewTreeProps extends ChakraTreeView.TreeProps {}

export const TreeViewTree = React.forwardRef<HTMLDivElement, TreeViewTreeProps>(
  function TreeViewTree(props, ref) {
    const { ...rest } = props;
    return <ChakraTreeView.Tree {...rest} ref={ref} />;
  },
);

export const TreeViewBranch = React.forwardRef<
  HTMLDivElement,
  ChakraTreeView.BranchProps
>(function TreeViewBranch(props, ref) {
  return <ChakraTreeView.Branch {...props} ref={ref} />;
});

export const TreeViewBranchControl = React.forwardRef<
  HTMLDivElement,
  ChakraTreeView.BranchControlProps
>(function TreeViewBranchControl(props, ref) {
  return <ChakraTreeView.BranchControl {...props} ref={ref} />;
});

export const TreeViewItem = React.forwardRef<
  HTMLDivElement,
  ChakraTreeView.ItemProps
>(function TreeViewItem(props, ref) {
  return <ChakraTreeView.Item {...props} ref={ref} />;
});

export const TreeViewLabel = ChakraTreeView.Label;
export const TreeViewBranchIndicator = ChakraTreeView.BranchIndicator;
export const TreeViewBranchText = ChakraTreeView.BranchText;
export const TreeViewBranchContent = ChakraTreeView.BranchContent;
export const TreeViewBranchIndentGuide = ChakraTreeView.BranchIndentGuide;
export const TreeViewItemText = ChakraTreeView.ItemText;
export const TreeViewNode = ChakraTreeView.Node;
export const TreeViewNodeProvider = ChakraTreeView.NodeProvider;

export const TreeView = {
  Root: TreeViewRoot,
  Label: TreeViewLabel,
  Tree: TreeViewTree,
  Branch: TreeViewBranch,
  BranchControl: TreeViewBranchControl,
  BranchIndicator: TreeViewBranchIndicator,
  BranchText: TreeViewBranchText,
  BranchContent: TreeViewBranchContent,
  BranchIndentGuide: TreeViewBranchIndentGuide,
  Item: TreeViewItem,
  ItemText: TreeViewItemText,
  Node: TreeViewNode,
  NodeProvider: TreeViewNodeProvider,
};
