import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React, { useContext } from 'react';
import cln from 'classnames';
import { ConfigContext } from '../config-provider/context';
import RcTabs, { TabPane } from '../components/rc-tabs';
import Icon from '../icon';
var DownLine = Icon.DownLine,
    DeleteLine = Icon.DeleteLine,
    CloseLine = Icon.CloseLine,
    PlusLine = Icon.PlusLine;
var Tabs = /*#__PURE__*/React.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 = _objectWithoutProperties(_ref, ["activeKey", "className", "type", "moreIcon", "hideAdd", "size", "tabLine", "editable", "addIcon", "deleteIcon", "onEdit", "isHoverClose", "activeTabNoBorderLine", "getPopupContainer"]);

  var tabRef = ref || React.useRef(null);

  var _useContext = useContext(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.createElement(DeleteLine, null) : /*#__PURE__*/React.createElement(CloseLine, null)),
      addIcon: addIcon || /*#__PURE__*/React.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 = cln((_cln = {}, _defineProperty(_cln, "".concat(tabsPrefix, "-card"), ['card'].includes(type)), _defineProperty(_cln, "".concat(tabsPrefix, "-").concat(sizeSuffixCls), !!sizeSuffixCls), _defineProperty(_cln, "".concat(tabsPrefix, "-bottomLine"), hasBottomLine()), _defineProperty(_cln, "".concat(tabsPrefix, "-activeTabNoBorderLine"), activeTabNoBorderLine), _defineProperty(_cln, "".concat(tabsPrefix, "-line"), type === 'line'), _defineProperty(_cln, "".concat(tabsPrefix, "-hover-close"), isHoverClose), _cln), className);

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

    return moreIcon;
  };

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