function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate 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 _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; }

import Interpolate from './Interpolate';
/**
 * 国际化函数
 * @param {String} remark 用于没有key时将直接显示remark
 * @param {String} key 将从国际化文件中获取此key的值
 * @param {Array} variable 替换值中的变量{0}{1}, 数组中支持String|String<html>|Number|Node类型
 * @param {Boolean} dangerouslyHTML 变量是否需要将变量html字符串转换成reactDOM显示
 * @return {Node} 返回reactDOM
 */

export default function (remark, key, variable, dangerouslyHTML) {
  var locale = window.localeData; // 如果没有参数, 则返回国际化数据

  if (Array.from(arguments).length === 0) {
    return locale;
  } // 渲染国际化数据中对应的值


  if (key && locale) {
    var value = locale[key]; // 构建变量映射: 将[variable0, variable1]转换成{'0': variable0, '1': variable1}

    var variableMap = {};

    if (value && variable && Array.isArray(variable) && variable.length) {
      for (var _iterator = _createForOfIteratorHelperLoose(variable.entries()), _step; !(_step = _iterator()).done;) {
        var _step$value = _step.value,
            index = _step$value[0],
            variableItem = _step$value[1];
        variableMap["" + index] = variableItem;
      }
    } // key的值value必须为string类型


    if (typeof value === 'string') {
      return Interpolate.variable(value, variableMap, dangerouslyHTML);
    }
  } // 没有国际化的值, 则渲染remark


  if (remark) return Interpolate.remark(remark, dangerouslyHTML);
  return '';
}