import React, { useState } from 'react';
import { faFolder } from '@fortawesome/free-solid-svg-icons/faFolder';
import { faFolderOpen } from '@fortawesome/free-solid-svg-icons/faFolderOpen';
import { useTreeNodeNavigation } from '../hooks';
import { FileTreeItem, FileTreeItemContent } from '.';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const FileTreeFolderComponent = ({
  item,
  renderBranch,
  FolderActions,
  actions,
  activateOnMouseOver = true,
  ItemContentComponent = FileTreeItemContent,
  testId = 'file-tree-folder',
  itemTestId = 'file-tree-item-wrapper',
  expand = false,
  disabled = false,
  itemContentComponentProps,
  rowSize
}) => {
  const [isOpen, openFolder] = useState(expand);
  const [isActive, setIsActive] = useState();
  const {
    treeItemAttrs,
    node,
    ref,
    toggleExpanded
  } = useTreeNodeNavigation({
    id: item.id,
    onToggleExpanded: openFolder
  });
  const currentLevel = node.parents.length + 1;
  const toggleFolder = () => {
    openFolder(!isOpen);
    setIsActive(!isOpen);
    toggleExpanded(!isOpen);
  };
  const onMouseOver = mouseEnter => setIsActive(mouseEnter);
  return /*#__PURE__*/_jsxs("li", {
    ref: ref,
    className: "branch-item",
    "data-id": `file-tree-item-${item.id}`,
    "test-id": `${itemTestId}-${currentLevel}`,
    ...treeItemAttrs,
    children: [/*#__PURE__*/_jsx(FileTreeItem, {
      item: item,
      ItemActions: FolderActions,
      actions: actions,
      isActive: isActive || node.isFocused,
      onClick: toggleFolder,
      onMouseOver: !disabled && activateOnMouseOver && onMouseOver || undefined,
      testId: testId,
      disabled: disabled,
      rowSize: rowSize,
      children: /*#__PURE__*/_jsx(ItemContentComponent, {
        item: item,
        isActive: isActive || node.isFocused,
        defaultIcon: isOpen ? faFolderOpen : faFolder,
        disabled: disabled,
        ...itemContentComponentProps
      })
    }), isOpen && item.content && renderBranch?.(item.content)]
  });
};
export default FileTreeFolderComponent;