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); }
export { logger, random, uuid, isEmpty, serialize, parseJSON } from '@irim/saber';

/**
 * 解析URL search
 * @param  {string}  [str]      要解析的字符串
 * @param  {Boolean} [isDecode=true] 是否decode
 * @return {object}
 * @example
 * parseParam('aaa=1&bbb=2&ccc=3'); // { aaa: '1', bbb: '2', ccc: '3' }
 */
export function parseParam() {
  var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : location.search || location.href;
  var isDecode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  var ary = str.split(/[?&]/);
  var result = {};
  for (var i = 0, j = ary.length; i < j; i++) {
    var n = ary[i];
    if (!n) continue;
    var tmp = n.split('=');
    result[tmp[0]] = isDecode && !!tmp[1] ? decodeURIComponent(tmp[1]) : tmp[1];
  }
  return result;
}

/**
 * 解析cookie
 * @return {object}
 */
export function parseCookie() {
  var cookieStr = window.document ? document.cookie : '';
  var cookieAry = cookieStr.split(/\s?;\s?/);
  var cookieMap = {};
  cookieAry.forEach(function (x) {
    var i = x.indexOf('=');
    if (i >= 0) {
      cookieMap[x.substring(0, i)] = x.substring(i + 1);
    }
  });
  return cookieMap;
}

/**
 * 从对象中解析出想要的值
 * @param {object} obj object
 * @param {string} key keys
 * @example
 * parseValue({ a: [{ b: 100 }] }, 'a.0.b'); // 100
 */
export function parseValue(obj, key) {
  if (!obj) return undefined;
  var keys = key.split('.');
  return keys.reduce(function (prev, curr) {
    return prev && prev[curr] || undefined;
  }, obj);
}
var SEED = Math.round(Date.now() * Math.random());

/** 返回一个唯一的key */
export function uniqueKey() {
  return "CC".concat((SEED++).toString(36).toUpperCase());
}

/**
 * 保留几位小数点
 * @param {number} num
 * @param {number} [unit=2]
 */
export function toFixed(num) {
  var fix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
  var unit = Math.pow(10, fix);
  return Math.round(num * unit) / unit;
}

// 复制文本到剪贴板
export function copy2Clipboard(text) {
  return new Promise(function (resolve, reject) {
    var input = document.createElement('input');
    input.style.position = 'fixed';
    input.style.opacity = '0';
    input.value = text;
    document.body.appendChild(input);
    input.select();
    document.execCommand('copy') ? resolve(true) : reject(false);
    document.body.removeChild(input);
  });
}

/** 字符串排序 */
export function compare4ASCII(a, b) {
  if (!a && !b) return 0;
  // if (!isNaN(a) && !isNaN(b)) return a - b;
  if (typeof a === 'number' && typeof b === 'number') return a - b;

  // 没有内容应该放最后
  if (!a) return -1;
  if (!b) return 1;
  if (a === b) return 0;
  var aIsEN = /^[\w\s]+$/.test(a);
  var bIsEN = /^[\w\s]+$/.test(b);
  if (aIsEN && bIsEN) return a > b ? 1 : -1;
  if (aIsEN && !bIsEN) return -1;
  if (!aIsEN && bIsEN) return 1;
  if (String.prototype.localeCompare) {
    return String.prototype.localeCompare.call(a, b, 'zh');
  }
  return a > b ? 1 : -1;
}
export var ENV = (document.querySelector('meta[name="x-server-env"]') || {
  content: 'test'
}).content;

/**
 * 在后端存在脏数据的情况下，为列表数据加上唯一key
 * @param data object 请求返回的数据
 * @param data.dataSource array
 * @param data.pagination object
 * @returns object
 */
export var getUniqueData = function getUniqueData(data) {
  var _ref = data || {},
    _ref$dataSource = _ref.dataSource,
    dataSource = _ref$dataSource === void 0 ? [] : _ref$dataSource,
    pagination = _ref.pagination;
  return {
    dataSource: dataSource.map(function (item, index) {
      return _objectSpread(_objectSpread({}, item), {}, {
        uniqueId: (pagination === null || pagination === void 0 ? void 0 : pagination.pageSize) * ((pagination === null || pagination === void 0 ? void 0 : pagination.pageNo) - 1) + index + 1
      });
    }),
    pagination: pagination
  };
};