"use strict";

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

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

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

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

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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 _omit = _interopRequireDefault(require("lodash/omit"));

var _toArray = _interopRequireDefault(require("lodash/toArray"));

var _isArray = _interopRequireDefault(require("lodash/isArray"));

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

var _CollapsePanel = _interopRequireDefault(require("./CollapsePanel"));

var _collapse = _interopRequireDefault(require("../rc-components/collapse"));

var _LocaleReceiver = _interopRequireDefault(require("../locale-provider/LocaleReceiver"));

var _default = _interopRequireDefault(require("../locale-provider/default"));

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

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

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

  function Collapse() {
    var _this;

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

    _this.renderExpandTextContent = function () {
      var _classNames;

      var panelProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var locale = arguments.length > 1 ? arguments[1] : undefined;
      var localeCode = arguments.length > 2 ? arguments[2] : undefined;
      var expandIconPositionCof = arguments.length > 3 ? arguments[3] : undefined;
      var customizePrefixCls = _this.props.prefixCls;
      var getPrefixCls = _this.context.getPrefixCls;
      var prefixCls = getPrefixCls('collapse', customizePrefixCls);
      var iconCls = (0, _classnames["default"])((_classNames = {}, (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-expand-icon"), true), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-expanded"), panelProps.isActive), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-collapsed"), !panelProps.isActive), _classNames));

      var icon = /*#__PURE__*/_react["default"].createElement("i", {
        className: iconCls
      });

      return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, expandIconPositionCof === 'left' && icon, panelProps.isActive ? /*#__PURE__*/_react["default"].createElement("span", {
        className: "".concat(prefixCls, "-expand-text"),
        style: {
          minWidth: localeCode === 'zh-cn' ? '0.38rem' : '0.52rem'
        }
      }, locale.fold) : /*#__PURE__*/_react["default"].createElement("span", {
        className: "".concat(prefixCls, "-expand-text"),
        style: {
          minWidth: localeCode === 'zh-cn' ? '0.38rem' : '0.52rem'
        }
      }, locale.unfold), expandIconPositionCof === 'right' && icon);
    };

    _this.renderItems = function () {
      var _this$props = _this.props,
          children = _this$props.children,
          parentCollapsible = _this$props.collapsible;
      var arrayChildren = children;

      if (!(0, _isArray["default"])(children)) {
        arrayChildren = [children];
      }

      return (0, _toArray["default"])(arrayChildren).map(function (child, index) {
        if ( /*#__PURE__*/(0, _react.isValidElement)(child)) {
          var key = child.key || String(index);
          var _child$props = child.props,
              disabled = _child$props.disabled,
              collapsible = _child$props.collapsible;

          if (disabled) {
            var childProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, (0, _omit["default"])(child.props, 'disabled')), {}, {
              key: key,
              disabled: collapsible && (collapsible === 'header' || collapsible === 'icon') ? false : disabled
            });
            return /*#__PURE__*/(0, _react.cloneElement)(child, childProps);
          }

          return /*#__PURE__*/(0, _react.cloneElement)(child, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, child.props), {}, {
            key: key,
            disabled: collapsible ? collapsible === 'disabled' : parentCollapsible === 'disabled'
          }));
        }

        return child;
      });
    };

    return _this;
  }

  (0, _createClass2["default"])(Collapse, [{
    key: "render",
    value: function render() {
      var _classNames2,
          _this2 = this;

      var _this$props2 = this.props,
          customizePrefixCls = _this$props2.prefixCls,
          _this$props2$classNam = _this$props2.className,
          className = _this$props2$classNam === void 0 ? '' : _this$props2$classNam,
          expandIcon = _this$props2.expandIcon,
          bordered = _this$props2.bordered,
          expandIconPosition = _this$props2.expandIconPosition,
          trigger = _this$props2.trigger,
          ghost = _this$props2.ghost;
      var _this$context = this.context,
          getPrefixCls = _this$context.getPrefixCls,
          getConfig = _this$context.getConfig;
      var prefixCls = getPrefixCls('collapse', customizePrefixCls);
      var expandIconPositionCof = expandIconPosition || getConfig('collapseExpandIconPosition');
      var expandIconCof = expandIcon || getConfig('collapseExpandIcon');
      var triggerCof = trigger || getConfig('collapseTrigger');
      var collapseClassName = (0, _classnames["default"])((_classNames2 = {}, (0, _defineProperty2["default"])(_classNames2, "".concat(prefixCls, "-borderless"), !bordered), (0, _defineProperty2["default"])(_classNames2, "".concat(prefixCls, "-text-action"), expandIconCof === 'text' && expandIconPositionCof === 'left'), (0, _defineProperty2["default"])(_classNames2, "".concat(prefixCls, "-trigger"), triggerCof === 'header'), (0, _defineProperty2["default"])(_classNames2, "".concat(prefixCls, "-ghost"), ghost), (0, _defineProperty2["default"])(_classNames2, "".concat(prefixCls, "-icon-position-").concat(expandIconPositionCof), true), _classNames2), className);
      var expandIconContent;

      if (typeof expandIconCof === 'function') {
        expandIconContent = function expandIconContent(panelProps) {
          return expandIconCof(panelProps);
        };
      } else if (expandIconCof === 'text') {
        expandIconContent = function expandIconContent(panelProps) {
          return /*#__PURE__*/_react["default"].createElement(_LocaleReceiver["default"], {
            componentName: "Collapse",
            defaultLocale: _default["default"].Collapse
          }, function (locale, localeCode) {
            return _this2.renderExpandTextContent(panelProps, locale, localeCode, expandIconPositionCof);
          });
        };
      }

      return /*#__PURE__*/_react["default"].createElement(_collapse["default"], (0, _extends2["default"])({}, this.props, {
        expandIcon: expandIconContent,
        expandIconPosition: expandIconPositionCof,
        prefixCls: prefixCls,
        className: collapseClassName
      }), this.renderItems());
    }
  }], [{
    key: "contextType",
    get: function get() {
      return _ConfigContext["default"];
    }
  }]);
  return Collapse;
}(_react.Component);

exports["default"] = Collapse;
Collapse.displayName = 'Collapse';
Collapse.Panel = _CollapsePanel["default"];
Collapse.defaultProps = {
  bordered: true,
  openAnimation: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _openAnimation["default"]), {}, {
    appear: function appear() {}
  })
};
//# sourceMappingURL=Collapse.js.map
