var _excluded = ["tab"];
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import React, { Component } from 'react';
import { Badge, Tabs as OriginalTabs } from 'antd';
import { warning } from "../../utils/warning";
import classNames from 'classnames';
import "./index.less";
var prefix = 'pisell-lowcode-';
var Tabs = /*#__PURE__*/function (_Component) {
  _inherits(Tabs, _Component);
  var _super = _createSuper(Tabs);
  function Tabs() {
    var _this$props$activeKey;
    var _this;
    _classCallCheck(this, Tabs);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _super.call.apply(_super, [this].concat(args));
    _defineProperty(_assertThisInitialized(_this), "state", {
      activeKey: (_this$props$activeKey = _this.props.activeKey) !== null && _this$props$activeKey !== void 0 ? _this$props$activeKey : _this.props.defaultActiveKey
    });
    _defineProperty(_assertThisInitialized(_this), "_handleChange", function (key) {
      _this.setActiveKey(key);
    });
    _defineProperty(_assertThisInitialized(_this), "setActiveKey", function (key) {
      var _this$props$onChange = _this.props.onChange,
        onChange = _this$props$onChange === void 0 ? function () {} : _this$props$onChange;
      _this.setState({
        activeKey: key
      });
      onChange(key);
    });
    _defineProperty(_assertThisInitialized(_this), "getActiveKey", function () {
      return _this.state.activeKey;
    });
    _defineProperty(_assertThisInitialized(_this), "renderIconLabelTabBar", function (props, DefaultTabBar) {
      var _this$props2;
      var _this$props = _this.props,
        items = _this$props.items,
        sidebarWidth = _this$props.sidebarWidth;
      var wrapStyle = {
        gap: props.tabBarGutter
      };
      if (['left', 'right'].includes(props.tabPosition)) {
        wrapStyle = _objectSpread(_objectSpread({}, wrapStyle), {}, {
          width: sidebarWidth || 130
        });
      }
      return /*#__PURE__*/React.createElement("div", {
        className: classNames('pisell-lowcode-tabs-nav', "".concat(prefix, "tab-bar-wrap"), "".concat(prefix, "tab-bar-wrap-").concat(props.tabPosition), (_this$props2 = _this.props) === null || _this$props2 === void 0 ? void 0 : _this$props2.className),
        style: wrapStyle
      }, _this.filterHiddenTabs(items).map(function (item) {
        return /*#__PURE__*/React.createElement("div", {
          className: classNames("".concat(prefix, "tab-bar-item"), _defineProperty({}, "".concat(prefix, "tab-bar-item-active"), item.key === props.activeKey)),
          key: item.key,
          onClick: function onClick(e) {
            return props.onTabClick(item.key, e);
          }
        }, /*#__PURE__*/React.createElement(Badge, {
          count: item.badge,
          offset: [0, 6]
        }, /*#__PURE__*/React.createElement("div", {
          className: "".concat(prefix, "tab-bar-icon-wrap")
        }, item.icon)), /*#__PURE__*/React.createElement("span", {
          className: "".concat(prefix, "tab-bar-label")
        }, item.label));
      }), props.extra);
    });
    _defineProperty(_assertThisInitialized(_this), "filterHiddenTabs", function (tabs) {
      return tabs.filter(function (item) {
        return !item.hidden;
      });
    });
    return _this;
  }
  _createClass(Tabs, [{
    key: "render",
    value: function render() {
      var props = this.props;
      var activeKey = this.state.activeKey;
      var children = props.children,
        type = props.type;
      var items = props.items;
      var otherProps = {};

      // props.items 存在，只认 props.items
      // 兼容代码：props.children 反推 props.items
      if (!props.items && Array.isArray(children) && children.length > 0) {
        warning('Tabs.TabPane is deprecated. Please use `items` directly.');
        items = children.map(function (node) {
          if ( /*#__PURE__*/React.isValidElement(node)) {
            var key = node.key,
              _props = node.props;
            var _ref = _props || {},
              tab = _ref.tab,
              restProps = _objectWithoutProperties(_ref, _excluded);
            var item = _objectSpread(_objectSpread({
              key: String(key)
            }, restProps), {}, {
              label: tab
            });
            return item;
          }
          return null;
        }).filter(Boolean);
      }
      items = this.filterHiddenTabs(items);
      if (type === 'icon-label') {
        otherProps = {
          renderTabBar: this.renderIconLabelTabBar,
          type: 'line'
        };
      }
      return /*#__PURE__*/React.createElement(OriginalTabs, _extends({}, props, otherProps, {
        items: items,
        activeKey: activeKey,
        onChange: this._handleChange
      }));
    }
  }]);
  return Tabs;
}(Component);
Tabs.TabPane = OriginalTabs.TabPane;
export default Tabs;