function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
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; }
/**
 * 字典 取值数据
 * author: shomychen
 * date: 2022.12.30
 */

/**
 * 字典值替换文本通用方法
 * @param {Array} dictOptions  字典数组
 * @param {String} text  字典值(多个可以用,隔开）
 * @param {Object} optionName  指定字段值（默认 { value: 'value', label: 'label' }）
 *
 * @return String
 */
export function filterDictText(dictOptions, text) {
  var optionName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
    value: 'value',
    label: 'label'
  };
  // -- 字典翻译 text 允许逗号分隔 ---
  var dictOptionName = optionName || {
    value: 'value',
    label: 'label'
  };
  if (text != null && Array.isArray(dictOptions)) {
    var result = [];
    // 允许多个逗号分隔，允许传数组对象
    var splitText;
    if (Array.isArray(text)) {
      splitText = text;
    } else {
      splitText = text.toString().trim().split(',');
    }
    var _iterator = _createForOfIteratorHelper(splitText),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var txt = _step.value;
        var dictText = txt;
        var _iterator2 = _createForOfIteratorHelper(dictOptions),
          _step2;
        try {
          for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
            var dictItem = _step2.value;
            if (txt.toString() === dictItem[dictOptionName.value || 'value'].toString()) {
              dictText = dictItem[dictOptionName.label || 'label'] || dictItem.text || dictItem.title;
              break;
            }
          }
        } catch (err) {
          _iterator2.e(err);
        } finally {
          _iterator2.f();
        }
        result.push(dictText);
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    return result.join(',');
  }
  return text;
  // -- 字典翻译 text 允许逗号分隔 ---
}

/**
 * 字典值替换文本通用方法(多选)
 * @param {Array}  dictOptions  字典数组
 * @param {String, Array} text  字典值(多个可以用,隔开或者是数组格式）
 * @param {Object} optionName  指定字段值（默认 { value: 'value', label: 'label' }）
 *
 * @return String
 */

export function filterMultiDictText(dictOptions, text) {
  var optionName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
    value: 'value',
    label: 'label'
  };
  // js “!text” 认为0为空，所以做提前处理
  var dictOptionName = optionName || {
    value: 'value',
    label: 'label'
  };
  if (text === 0 || text === '0') {
    if (dictOptions) {
      var _iterator3 = _createForOfIteratorHelper(dictOptions),
        _step3;
      try {
        for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
          var dictItem = _step3.value;
          if (text == dictItem[dictOptionName.value || 'value']) {
            return dictItem[dictOptionName.label || 'label'] || dictItem.text || dictItem.title;
          }
        }
      } catch (err) {
        _iterator3.e(err);
      } finally {
        _iterator3.f();
      }
    }
  }
  if (!text || text == 'null' || !dictOptions || dictOptions.length == 0) {
    return "";
  }
  var re = "";
  text = text.toString();
  var arr = text.split(",");
  dictOptions.forEach(function (option) {
    if (option) {
      for (var i = 0; i < arr.length; i++) {
        if (arr[i] === option[dictOptionName.value || 'value']) {
          re += (option[dictOptionName.label || 'label'] || option.text || option.title) + ",";
          break;
        }
      }
    }
  });
  if (re == "") {
    return text;
  }
  return re.substring(0, re.length - 1);
}

/**
 * 转换数据字典value为整型
 * @param {Array} dictOptions  字典数组
 *
 * @return Array
 * */

export function transformDictValue(dictOptions) {
  if (Array.isArray(dictOptions)) {
    return dictOptions.map(function (option) {
      return _objectSpread(_objectSpread({}, option), {}, {
        value: Number(option.value)
      });
    });
  } else {
    return dictOptions;
  }
}