import { _ as _extends } from '../_rollupPluginBabelHelpers-736b301a.js';
import React__default from 'react';
import { P as PropTypes } from '../index-71189681.js';
import { Tree } from 'antd';
import IconFont from '../IconFont/index.js';
import HightLevel from '../HightLevel/index.js';
import '../_commonjsHelpers-e7b0df42.js';
import 'react-is';
import '@zenview/micro-utils';
import 'lodash';

const TreeNode = Tree.TreeNode;
class TreeView extends React__default.Component {
  constructor() {
    super();
    this.renderTreeNodes = list => {
      const {
        treeNodeProps = {}
      } = this.props;
      const {
        treeNodeClass,
        prefix,
        suffix,
        treeNodeIcon,
        keyword,
        disableCheckbox,
        key = 'id',
        nameKey = 'name',
        RenderTreeTitle
      } = treeNodeProps;
      const whatClass = treeNodeClass ? treeNodeClass : () => '';
      const nodeProps = {};
      const disable = disableCheckbox ? disableCheckbox : () => false;
      return list.map(node => {
        const className = whatClass(node);
        if (treeNodeIcon) {
          nodeProps.icon = treeNodeIcon(node);
        }
        if (disableCheckbox) {
          nodeProps.disableCheckbox = disable(node);
        }
        return /*#__PURE__*/React__default.createElement(TreeNode, _extends({}, nodeProps, {
          className: className,
          title: /*#__PURE__*/React__default.createElement(TreeNodeTitle, {
            node: node,
            nameKey: nameKey,
            keyword: keyword,
            prefix: prefix,
            suffix: suffix,
            RenderTreeTitle: RenderTreeTitle
          }),
          key: node[key],
          dataRef: node,
          isLeaf: node.isLeaf
        }), node.children && this.renderTreeNodes(node.children));
      });
    };
    this.treeRef = /*#__PURE__*/React__default.createRef();
  }
  getCheckedKeys() {
    if (!this.props.checkable || !this.treeRef.current) {
      return [];
    }
    return this.treeRef.current.tree.state.checkedKeys;
  }
  render() {
    const {
      className = '',
      treeData = [],
      showIcon = true,
      treeNodeProps,
      ...props
    } = this.props;
    return /*#__PURE__*/React__default.createElement(Tree, _extends({
      className: `lm-base-tree-component ${className}`,
      showIcon: showIcon,
      ref: this.treeRef,
      switcherIcon: /*#__PURE__*/React__default.createElement(IconFont, {
        style: {
          fontSize: 20,
          verticalAlign: '-0.4em'
        },
        type: "icon-S_Arrow_SmallDown"
      })
    }, props), this.renderTreeNodes(treeData));
  }
}
TreeView.propTypes = {
  treeNodeProps: PropTypes.shape({
    treeNodeClass: PropTypes.func,
    prefix: PropTypes.func,
    suffix: PropTypes.func,
    treeNodeIcon: PropTypes.func,
    disableCheckbox: PropTypes.func
  })
};
function TreeNodeTitle({
  node,
  nameKey,
  prefix,
  keyword,
  suffix,
  RenderTreeTitle
}) {
  if (RenderTreeTitle) {
    return /*#__PURE__*/React__default.createElement(RenderTreeTitle, {
      node: node,
      nameKey: nameKey,
      keyword: keyword
    });
  }
  return /*#__PURE__*/React__default.createElement("span", {
    title: node[nameKey]
  }, prefix && prefix(node), /*#__PURE__*/React__default.createElement(HightLevel, {
    keyword: keyword,
    name: node[nameKey]
  }), suffix && suffix(node));
}

export { TreeView as default };
//# sourceMappingURL=index.js.map
