"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _tabs = _interopRequireDefault(require("antd/lib/tabs"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _react = _interopRequireWildcard(require("react"));
var _warning = require("../../utils/warning");
var _excluded = ["tab"];
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var Tabs = /*#__PURE__*/function (_Component) {
  (0, _inheritsLoose2["default"])(Tabs, _Component);
  function Tabs() {
    var _this$props$activeKey;
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _Component.call.apply(_Component, [this].concat(args)) || this;
    _this.state = {
      activeKey: (_this$props$activeKey = _this.props.activeKey) !== null && _this$props$activeKey !== void 0 ? _this$props$activeKey : _this.props.defaultActiveKey
    };
    _this._handleChange = function (key) {
      _this.setActiveKey(key);
    };
    // 编辑器里可以通过 this.$(refId).setActiveKey(key) 调用
    _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);
    };
    // 编辑器里可以通过 this.$(refId).getActiveKey() 调用
    _this.getActiveKey = function () {
      return _this.state.activeKey;
    };
    return _this;
  }
  var _proto = Tabs.prototype;
  _proto.render = function render() {
    var props = this.props;
    var activeKey = this.state.activeKey;
    var children = props.children;
    var items = props.items;

    // props.items 存在，只认 props.items
    // 兼容代码：props.childrens 反推 props.items
    if (!props.items && Array.isArray(children) && children.length > 0) {
      (0, _warning.warning)('Tabs.TabPane is deprecated. Please use `items` directly.');
      items = children.map(function (node) {
        if ( /*#__PURE__*/_react["default"].isValidElement(node)) {
          var key = node.key,
            _props = node.props;
          var _ref = _props || {},
            tab = _ref.tab,
            restProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
          var item = (0, _extends2["default"])({
            key: String(key)
          }, restProps, {
            label: tab
          });
          return item;
        }
        return null;
      }).filter(Boolean);
    }
    return /*#__PURE__*/_react["default"].createElement(_tabs["default"], (0, _extends2["default"])({}, props, {
      items: items,
      activeKey: activeKey,
      onChange: this._handleChange
    }));
  };
  return Tabs;
}(_react.Component);
Tabs.TabPane = _tabs["default"].TabPane;
var _default = exports["default"] = Tabs;