"use strict";

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

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

var _antd = require("antd");

var _qs = require("qs");

var _indexModule = _interopRequireDefault(require("./index.module.less"));

var _Container = _interopRequireDefault(require("../Container"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var TabPane = _antd.Tabs.TabPane;

function _default() {
  var _Container$useContain = _Container.default.useContainer(),
      api = _Container$useContain.api,
      type = _Container$useContain.type,
      setType = _Container$useContain.setType,
      setActiveResource = _Container$useContain.setActiveResource;

  var callRemote = api.callRemote,
      intl = api.intl;

  var getQueryConfig = function getQueryConfig() {
    return (0, _qs.parse)(window.location.search.substr(1));
  };

  var updateUrlQuery = function updateUrlQuery(params) {
    var defaultParas = getQueryConfig();
    window.history.pushState({}, '', "?".concat((0, _qs.stringify)(_objectSpread({}, defaultParas, {}, params))));
  };

  return /*#__PURE__*/_react.default.createElement(_antd.Tabs, {
    className: _indexModule.default.tabs,
    size: "large",
    activeKey: type,
    onChange: function onChange(activeKey) {
      setType(activeKey);
      setActiveResource(null);
      /**
       * 修改 url 中的参数，数据源改变时
       * 清空 resource
       */

      updateUrlQuery({
        type: activeKey,
        resource: undefined
      });
    }
  }, /*#__PURE__*/_react.default.createElement(TabPane, {
    tab: intl({
      id: 'org.umi.ui.blocks.tabs.blocks'
    }),
    key: "block"
  }), /*#__PURE__*/_react.default.createElement(TabPane, {
    tab: intl({
      id: 'org.umi.ui.blocks.tabs.templates'
    }),
    key: "template"
  }));
}