import { _ as _extends } from '../_rollupPluginBabelHelpers-736b301a.js';
import React__default from 'react';
import TreeView from '../Tree/index.js';
import { inject, observer } from 'mobx-react';
import IconFont from '../IconFont/index.js';
import { treeHelper } from '@zenview/micro-utils';
import { Checkbox } from 'antd';
import '../index-71189681.js';
import '../_commonjsHelpers-e7b0df42.js';
import 'react-is';
import '../HightLevel/index.js';
import 'lodash';

var _dec, _class;
let PlaceTreeWithExpend = (_dec = inject('place'), _dec(_class = observer(_class = class PlaceTreeWithExpend extends React__default.Component {
  constructor(props) {
    super(props);
    this.onExpand = expandedKeys => {
      this.setState({
        expandedKeys
      });
    };
    this.renderSuffix = node => {
      const {
        showCount,
        renderSuffix
      } = this.props;
      if (!renderSuffix && !showCount) {
        return null;
      }
      return /*#__PURE__*/React__default.createElement("span", {
        className: "tree-node-suffix"
      }, showCount && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("i", {
        className: "online-count"
      }, node.deviceCount.onlineCount, "/"), /*#__PURE__*/React__default.createElement("i", {
        className: "count"
      }, node.deviceCount.count)), renderSuffix && renderSuffix(node));
    };
    this.onChange = flag => {
      let {
        placeList
      } = this.props.place;
      const ids = flag ? placeList.map(v => v.placeId) : [placeList.filter(v => v.level !== 0)[0].placeId];
      this.setState({
        expandedKeys: ids
      });
    };
    const {
      expandedKeys: _expandedKeys
    } = this.props;
    this.state = {
      expandedKeys: _expandedKeys
    };
  }
  static getDerivedStateFromProps(props, state) {
    const options = {};
    if (!state.expandedKeys && props.expandedKeys) {
      options.expandedKeys = props.expandedKeys;
    }
    if (Object.keys(options).length > 0) {
      return options;
    }
    return null;
  }
  render() {
    const {
      place,
      className = '',
      disableCheckbox = false,
      renderHeader,
      treeNodeClass,
      activeKey,
      treeData,
      RenderTreeTitle,
      hasHeader = true,
      ...props
    } = this.props;
    const {
      expandedKeys
    } = this.state;
    const treeDatas = treeData || treeHelper.computPlaceTree(place.placeList);
    return /*#__PURE__*/React__default.createElement("div", {
      className: `lm-c-place-tree ${className}`
    }, renderHeader && renderHeader(), hasHeader && /*#__PURE__*/React__default.createElement("div", {
      className: "place-tree-header"
    }, /*#__PURE__*/React__default.createElement("div", {
      className: "place-tree-header-icon"
    }, /*#__PURE__*/React__default.createElement(IconFont, {
      type: "icon-S_Place_Place"
    }), "\u573A\u6240"), /*#__PURE__*/React__default.createElement(Checkbox, {
      onChange: e => this.onChange(e.target.checked)
    }, "\u5C55\u5F00\u5168\u90E8")), /*#__PURE__*/React__default.createElement(TreeView, _extends({}, props, {
      treeData: treeDatas,
      onExpand: this.onExpand,
      selectedKeys: [activeKey],
      expandedKeys: expandedKeys,
      treeNodeProps: {
        treeNodeIcon: node => /*#__PURE__*/React__default.createElement(IconFont, {
          type: `${node.level >= 5 ? 'icon-S_Place_Place' : 'icon-S_Bar_Add'}`
        }),
        key: 'id',
        nameKey: 'areaName',
        suffix: this.renderSuffix,
        treeNodeClass: treeNodeClass,
        disableCheckbox: disableCheckbox,
        RenderTreeTitle: RenderTreeTitle
      }
    })));
  }
}) || _class) || _class);

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