import React, { Component } from 'react';
import { Tree, Icon } from 'antd';
import './index.less';

class TreeLayout extends Component {
  getItem(item) {
    const { isHidden } = this.props;
    if (item.hidden || (isHidden && isHidden(item))) return <Tree.TreeNode className="hidden" />;
    if (item.children && item.children.length > 0) {
      return (
        <Tree.TreeNode {...item} icon={<Icon type={item.icon} />}>
          <div>12312</div>
          {item.children.map(subItem => {
            return this.getItem(subItem);
          })}
        </Tree.TreeNode>
      );
    }
    return <Tree.TreeNode {...item} icon={<Icon type={item.icon} />} />;
  }

  render() {
    const { itemList = [] } = this.props;
    return (
      <div className="tree-layout">
        {itemList.length > 0 && (
          <Tree {...this.props}>
            {itemList.map(item => {
              return this.getItem(item);
            })}
          </Tree>
        )}
      </div>
    );
  }
}

export default TreeLayout;
