import _Tabs from "antd/es/tabs";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
var _excluded = ["tab"];
import React, { Component } from 'react';
import { warning } from "../../utils/warning";
var Tabs = /*#__PURE__*/function (_Component) {
  _inheritsLoose(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) {
      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 = _objectWithoutPropertiesLoose(_ref, _excluded);
          var item = _extends({
            key: String(key)
          }, restProps, {
            label: tab
          });
          return item;
        }
        return null;
      }).filter(Boolean);
    }
    return /*#__PURE__*/React.createElement(_Tabs, _extends({}, props, {
      items: items,
      activeKey: activeKey,
      onChange: this._handleChange
    }));
  };
  return Tabs;
}(Component);
Tabs.TabPane = _Tabs.TabPane;
export default Tabs;