"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "TreeNode", {
  enumerable: true,
  get: function get() {
    return _tree.TreeNode;
  }
});
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _DirectoryTree = _interopRequireDefault(require("./DirectoryTree"));

var _openAnimation = _interopRequireDefault(require("../_util/openAnimation"));

var _tree = _interopRequireWildcard(require("../rc-components/tree"));

var _icon = _interopRequireDefault(require("../icon"));

var _progress = _interopRequireDefault(require("../progress"));

var _enum = require("../progress/enum");

var _enum2 = require("../_util/enum");

var _reactNode = require("../_util/reactNode");

var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));

var Tree = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(Tree, _Component);

  var _super = (0, _createSuper2["default"])(Tree);

  function Tree() {
    var _this;

    (0, _classCallCheck2["default"])(this, Tree);
    _this = _super.apply(this, arguments);

    _this.renderSwitcherIcon = function (_ref) {
      var isLeaf = _ref.isLeaf,
          loading = _ref.loading;
      var _this$props = _this.props,
          showLine = _this$props.showLine,
          switcherIcon = _this$props.switcherIcon;

      var prefixCls = _this.getPrefixCls();

      if (loading) {
        return /*#__PURE__*/_react["default"].createElement(_progress["default"], {
          type: _enum.ProgressType.loading,
          className: "".concat(prefixCls, "-switcher-loading-icon"),
          size: _enum2.Size.small
        });
      }

      var switcherCls = "".concat(prefixCls, "-switcher-icon");
      var showLeafIcon;

      if (showLine && (0, _typeof2["default"])(showLine) === 'object') {
        showLeafIcon = showLine.showLeafIcon;
      }

      if (isLeaf) {
        if (showLine) {
          if ((0, _typeof2["default"])(showLine) === 'object' && !showLeafIcon) {
            return /*#__PURE__*/_react["default"].createElement("span", {
              className: "".concat(prefixCls, "-switcher-leaf-line")
            });
          }

          return /*#__PURE__*/_react["default"].createElement(_icon["default"], {
            type: "note",
            className: "".concat(prefixCls, "-switcher-line-icon")
          });
        }

        return null;
      }

      if ((0, _reactNode.isValidElement)(switcherIcon)) {
        var switcherOriginCls = switcherIcon.props.className || '';
        return (0, _reactNode.cloneElement)(switcherIcon, {
          className: [switcherOriginCls, switcherCls]
        });
      }

      return /*#__PURE__*/_react["default"].createElement(_icon["default"], {
        type: "arrow_drop_down",
        className: switcherCls
      });
    };

    _this.setTreeRef = function (node) {
      _this.tree = node;
    };

    return _this;
  }

  (0, _createClass2["default"])(Tree, [{
    key: "getPrefixCls",
    value: function getPrefixCls() {
      var prefixCls = this.props.prefixCls;
      var getPrefixCls = this.context.getPrefixCls;
      return getPrefixCls('tree', prefixCls);
    }
  }, {
    key: "onKeyDown",
    value: function onKeyDown(e) {
      this.tree.onKeyDown(e);
      return e.isDefaultPrevented();
    }
  }, {
    key: "render",
    value: function render() {
      var props = this.props;
      var className = props.className,
          showIcon = props.showIcon,
          showLine = props.showLine,
          children = props.children,
          checkable = props.checkable;
      var prefixCls = this.getPrefixCls();
      var newProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, props), {}, {
        showLine: Boolean(showLine)
      });
      return /*#__PURE__*/_react["default"].createElement(_tree["default"], (0, _extends2["default"])({
        itemHeight: 20,
        ref: this.setTreeRef
      }, newProps, {
        className: (0, _classnames["default"])(!showIcon && "".concat(prefixCls, "-icon-hide"), className),
        checkable: checkable ? /*#__PURE__*/_react["default"].createElement("span", {
          className: "".concat(prefixCls, "-checkbox-inner")
        }) : 0,
        switcherIcon: this.renderSwitcherIcon,
        prefixCls: prefixCls
      }), children);
    }
  }], [{
    key: "contextType",
    get: function get() {
      return _ConfigContext["default"];
    }
  }]);
  return Tree;
}(_react.Component);

exports["default"] = Tree;
Tree.displayName = 'Tree';
Tree.TreeNode = _tree.TreeNode;
Tree.DirectoryTree = _DirectoryTree["default"];
Tree.defaultProps = {
  checkable: false,
  showIcon: false,
  openAnimation: _openAnimation["default"]
};
//# sourceMappingURL=index.js.map
