"use strict";

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

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

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

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

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

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

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

var _context = require("../config-provider/context");

var _rcTabs = _interopRequireWildcard(require("../components/rc-tabs"));

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

var DownLine = _icon.default.DownLine,
    DeleteLine = _icon.default.DeleteLine,
    CloseLine = _icon.default.CloseLine,
    PlusLine = _icon.default.PlusLine;

var Tabs = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
  var _cln;

  var activeKey = _ref.activeKey,
      className = _ref.className,
      _ref$type = _ref.type,
      type = _ref$type === void 0 ? 'line' : _ref$type,
      moreIcon = _ref.moreIcon,
      hideAdd = _ref.hideAdd,
      customSize = _ref.size,
      tabLine = _ref.tabLine,
      editable = _ref.editable,
      addIcon = _ref.addIcon,
      deleteIcon = _ref.deleteIcon,
      _onEdit = _ref.onEdit,
      isHoverClose = _ref.isHoverClose,
      activeTabNoBorderLine = _ref.activeTabNoBorderLine,
      outerGetPopupContainer = _ref.getPopupContainer,
      resetProps = (0, _objectWithoutProperties2.default)(_ref, ["activeKey", "className", "type", "moreIcon", "hideAdd", "size", "tabLine", "editable", "addIcon", "deleteIcon", "onEdit", "isHoverClose", "activeTabNoBorderLine", "getPopupContainer"]);

  var tabRef = ref || _react.default.useRef(null);

  var _useContext = (0, _react.useContext)(_context.ConfigContext),
      getPrefixClassName = _useContext.getPrefixClassName,
      size = _useContext.size,
      getPopupContainer = _useContext.getPopupContainer;

  var tabsPrefix = getPrefixClassName('tabs');
  var endSize = customSize || size;
  var editableConfig;

  if (editable) {
    editableConfig = {
      onEdit: function onEdit(editType, _ref2) {
        var key = _ref2.key,
            event = _ref2.event;
        _onEdit === null || _onEdit === void 0 ? void 0 : _onEdit(editType === 'add' ? event : key, editType);
      },
      removeIcon: deleteIcon || (type === 'line' ? /*#__PURE__*/_react.default.createElement(DeleteLine, null) : /*#__PURE__*/_react.default.createElement(CloseLine, null)),
      addIcon: addIcon || /*#__PURE__*/_react.default.createElement(PlusLine, null),
      showAdd: hideAdd !== true
    };
  }

  var rcActiveKey = activeKey === null || activeKey === void 0 ? void 0 : activeKey.toString();

  var getSizeSuffixCls = function getSizeSuffixCls() {
    if (endSize === 'small') return 'sm';
    if (endSize === 'large') return 'lg';
    return '';
  };

  var sizeSuffixCls = getSizeSuffixCls();

  var hasBottomLine = function hasBottomLine() {
    if (type === 'card' && tabLine !== false) {
      return true;
    }

    return tabLine;
  };

  var endClassName = (0, _classnames.default)((_cln = {}, (0, _defineProperty2.default)(_cln, "".concat(tabsPrefix, "-card"), ['card'].includes(type)), (0, _defineProperty2.default)(_cln, "".concat(tabsPrefix, "-").concat(sizeSuffixCls), !!sizeSuffixCls), (0, _defineProperty2.default)(_cln, "".concat(tabsPrefix, "-bottomLine"), hasBottomLine()), (0, _defineProperty2.default)(_cln, "".concat(tabsPrefix, "-activeTabNoBorderLine"), activeTabNoBorderLine), (0, _defineProperty2.default)(_cln, "".concat(tabsPrefix, "-line"), type === 'line'), (0, _defineProperty2.default)(_cln, "".concat(tabsPrefix, "-hover-close"), isHoverClose), _cln), className);

  var curMoreIcon = function curMoreIcon() {
    if (!moreIcon) {
      return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "\u66F4\u591A", /*#__PURE__*/_react.default.createElement(DownLine, {
        style: {
          marginLeft: '4px'
        }
      }));
    }

    return moreIcon;
  };

  return /*#__PURE__*/_react.default.createElement(_rcTabs.default, Object.assign({
    activeKey: rcActiveKey,
    ref: tabRef,
    className: endClassName,
    prefixCls: tabsPrefix,
    moreIcon: curMoreIcon(),
    editable: editableConfig,
    getPopupContainer: outerGetPopupContainer || getPopupContainer
  }, resetProps));
});

var _default = Object.assign(Tabs, {
  TabPane: _rcTabs.TabPane
});

exports.default = _default;