// 内库使用-start
import LocaleUtil from "./../../../../utils/LocaleUtil";
import Request from "./../../../../utils/Request";
// 内库使用-end

/* 测试使用-start
import { LocaleUtil, Request } from 'seedsui-react'
测试使用-end */

function loadCountryRegions() {
  var countryId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '86';
  return new Promise(function (resolve) {
    var _window$countryProvin;
    var language = window.seedsLocaleLanguage || 'zh_CN';

    // 测试，后台完成后删除此段
    // window.countryProvinces = {
    //   86: require('library/components/Cascader/utils/data/chinaData')
    // }

    // 优先读取缓存
    window.countryProvinces = window.countryProvinces || JSON.parse(window.sessionStorage.getItem('countryProvinces') || '{}');
    if ((_window$countryProvin = window.countryProvinces) !== null && _window$countryProvin !== void 0 && _window$countryProvin[countryId]) {
      resolve(window.countryProvinces[countryId]);
      return;
    }

    // 加载语言对应的文件
    Request.get("https://url/".concat(language, "/").concat(countryId, ".json")).then(function (list) {
      // 存到缓存中
      window.countryProvinces = JSON.parse(window.sessionStorage.getItem('countryProvinces') || '{}');
      window.countryProvinces[countryId] = list || [];
      window.sessionStorage.setItem('countryProvinces', JSON.stringify(window.countryProvinces));
      resolve(window.countryProvinces[countryId]);
    }).catch(function () {
      resolve(LocaleUtil.locale('获取省市区数据失败', 'SeedsUI_cascader_countryRegions_error'));
    });
  });
}
export default loadCountryRegions;