function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

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, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || 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; } 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 : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

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; }

import React from 'react';
import PropTypes from 'prop-types';
import { CascaderSelect } from 'mkui-ext';
import { replaceKeys } from '../_util/jsonUtils'; // 预设的热门城市：
// 北京(ZH1_0_00)、上海(ZH4_0_00)、广州(ZH9_4_01)、深圳(ZH9_15_01)、杭州(ZH32_1_01)、
// 天津(ZH2_0_00)、成都(ZH28_3_01)、重庆(ZH33_0_00)、哈尔滨(ZH15_3_01)、南京(ZH19_4_01)

var defaultFrequent = ['ZH1_0_00', 'ZH4_0_00', 'ZH9_4_01', 'ZH9_15_01', 'ZH32_1_01', 'ZH2_0_00', 'ZH28_3_01', 'ZH33_0_00', 'ZH15_3_01', 'ZH19_4_01']; // 需要替换的key

var replaceKeyMap = {
  countryCode: 'value',
  provinceCode: 'value',
  cityCode: 'value',
  regionCode: 'value',
  countryName: 'label',
  provinceName: 'label',
  cityName: 'label',
  regionName: 'label',
  provinces: 'children',
  cities: 'children',
  regions: 'children'
};

var AddressSelect = /*#__PURE__*/function (_React$Component) {
  _inherits(AddressSelect, _React$Component);

  var _super = _createSuper(AddressSelect);

  function AddressSelect() {
    var _this;

    _classCallCheck(this, AddressSelect);

    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), "formatData", function (data) {
      var domestic = data.domestic;

      var countries = _toConsumableArray(data.abroad.countries);

      countries.unshift({
        countryCode: domestic.code,
        countryName: domestic.name,
        provinces: domestic.provinces
      });
      return countries;
    });

    _defineProperty(_assertThisInitialized(_this), "apiAdapter", function () {
      var api = _this.props.api;
      return new Promise(function (resolve) {
        api().then(function (res) {
          var data = _this.formatData(res);

          data = replaceKeys(data, replaceKeyMap);
          resolve(data);
        });
      });
    });

    return _this;
  }

  _createClass(AddressSelect, [{
    key: "render",
    value:
    /** *******************render************************** */
    function render() {
      var _this$props = this.props,
          value = _this$props.value,
          onChange = _this$props.onChange,
          disabled = _this$props.disabled,
          frequentStorageKey = _this$props.frequentStorageKey;
      return /*#__PURE__*/React.createElement(CascaderSelect, {
        api: this.apiAdapter,
        disabled: disabled,
        lazyLoad: true,
        hasFrequent: true,
        defaultFrequent: defaultFrequent,
        frequentStorageKey: frequentStorageKey,
        value: value,
        placeholder: "\u8BF7\u9009\u62E9",
        searchPlaceholder: "\u8BF7\u8F93\u5165\u57CE\u5E02\u540D\u79F0\u3001\u62FC\u97F3\u6216\u7B80\u79F0\uFF0C\u5982\uFF1A\u676D\u5DDE\uFF0CHangzhou\uFF0CHZ",
        onChange: onChange
      });
    }
  }]);

  return AddressSelect;
}(React.Component);

_defineProperty(AddressSelect, "propTypes", {
  onChange: PropTypes.func,
  api: PropTypes.func,
  value: PropTypes.object,
  frequentStorageKey: PropTypes.string
});

_defineProperty(AddressSelect, "defaultProps", {
  onChange: null,
  api: null,
  value: null,
  frequentStorageKey: 'often.place'
});

export default AddressSelect;
//# sourceMappingURL=AddressSelect.js.map
