import React from 'react';
import Tree from 'antd/es/tree';
import 'antd/es/tree/style';
import { FILE_NODE_TYPE } from '../../../core/constants';
import './ExplorerBar.less';
var DirectoryTree = Tree.DirectoryTree;
var TreeNode = Tree.TreeNode;

var buildNodes = function buildNodes(tree) {
  return (!tree ? [] : tree).filter(function (n) {
    return !!n;
  }).map(function (node) {
    if (node.data.type === FILE_NODE_TYPE) {
      return React.createElement(TreeNode, {
        title: node.data.name,
        key: node.data.path,
        isLeaf: true
      });
    }

    return React.createElement(TreeNode, {
      title: node.data.name,
      key: node.data.path
    }, buildNodes(node.children));
  });
};

export default (function (_ref) {
  var nodesTree = _ref.nodesTree,
      onFileClick = _ref.onFileClick,
      onFolderClick = _ref.onFolderClick,
      filesMap = _ref.filesMap,
      foldersMap = _ref.foldersMap;

  if (!nodesTree || !nodesTree.length || !nodesTree[0]) {
    return null;
  }

  var rootPath = nodesTree[0].data.path;
  return React.createElement("div", {
    className: "ExplorerBar"
  }, React.createElement("div", {
    className: "body"
  }, React.createElement(DirectoryTree, {
    showIcon: true,
    defaultExpandedKeys: [rootPath],
    onSelect: function onSelect(path) {
      return filesMap[path] && onFileClick(filesMap[path]);
    },
    onExpand: function onExpand(path) {
      return foldersMap[path] && onFolderClick(foldersMap[path]);
    }
  }, buildNodes(nodesTree))));
});