"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _faFolder = require("@fortawesome/free-solid-svg-icons/faFolder");
var _faFolderOpen = require("@fortawesome/free-solid-svg-icons/faFolderOpen");
var _hooks = require("../hooks");
var _ = require(".");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
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] = (0, _react.useState)(expand);
  const [isActive, setIsActive] = (0, _react.useState)();
  const {
    treeItemAttrs,
    node,
    ref,
    toggleExpanded
  } = (0, _hooks.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__*/(0, _jsxRuntime.jsxs)("li", {
    ref: ref,
    className: "branch-item",
    "data-id": `file-tree-item-${item.id}`,
    "test-id": `${itemTestId}-${currentLevel}`,
    ...treeItemAttrs,
    children: [/*#__PURE__*/(0, _jsxRuntime.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__*/(0, _jsxRuntime.jsx)(ItemContentComponent, {
        item: item,
        isActive: isActive || node.isFocused,
        defaultIcon: isOpen ? _faFolderOpen.faFolderOpen : _faFolder.faFolder,
        disabled: disabled,
        ...itemContentComponentProps
      })
    }), isOpen && item.content && renderBranch?.(item.content)]
  });
};
var _default = exports.default = FileTreeFolderComponent;