"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.transSearchByColumn = exports.isUrl = exports.isHttpUrl = exports.getJumpUrlBySearch = void 0;
var _qs = require("qs");
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); } // @ts-nocheck 文件忽略(添加到该文件的首行)
/**
 *  跳转外链、iframe 地址支持带参
 *  获取url的search，并有条件：`^{变量名}`的条件取本地存储的数据 // 参数格式：^{变量名} 变量名支持数字、字母、下划线
 *  根据url上的参数变量，重新调整跳转链接
 *  @param {string} href 地址
 *
 *  @result {string} 完整的url地址
 * */
var getJumpUrlBySearch = exports.getJumpUrlBySearch = function getJumpUrlBySearch(href) {
  var searchKeys = {};
  var getPath;
  if (!href) return;
  if (isHttpUrl(href)) {
    var url = new URL(href);
    searchKeys = (0, _qs.parse)(url.search, {
      ignoreQueryPrefix: true // 去除第一个字符'?'
    });
    getPath = url.origin + url.pathname; // 取条件参数外的地址
  } else {
    searchKeys = (0, _qs.parse)(href.split('?')[1], {
      ignoreQueryPrefix: true // 去除第一个字符'?'
    });
    getPath = href.split('?').length > 0 ? href.split('?')[0] : ''; // 取条件参数外的地址
  }
  // 有带参数，取本地的数据，然后拼接给地址
  Object.keys(searchKeys).forEach(function (item, index) {
    var _searchKeys$item;
    // 取变量名
    if (((_searchKeys$item = searchKeys[item]) === null || _searchKeys$item === void 0 ? void 0 : _searchKeys$item.indexOf('^{')) !== -1) {
      // 清除"^{"与"}"取当前的
      var keyParam = searchKeys[item].replace('^{', '').substring(0, searchKeys[item].replace('^{', '').lastIndexOf('}'));
      searchKeys[item] = localStorage.getItem(keyParam) || '';
    }
    getPath += (index === 0 ? "?" : '&') + item + "=" + searchKeys[item];
  });
  return getPath;
};

/**
 *  是否是完整的URL
 *
 * */
var isHttpUrl = exports.isHttpUrl = function isHttpUrl(path) {
  if (!path.startsWith('http')) {
    return false;
  }
  try {
    var url = new URL(path);
    return !!url;
  } catch (error) {
    return false;
  }
};

/* eslint no-useless-escape:0 import/prefer-default-export:0 */
var reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;

/**
 *  是否是完整的URL
 * */
var isUrl = exports.isUrl = function isUrl(path) {
  return reg.test(path);
};

/***
 * transSearchByColumn URL上带orders[xxx]=xxx相关参数值，转换成order排序数组
 * @param searchParams     url上的search参数
 * @param transOptionName = 'orders'               // 提交需要的字段名
 */
var transSearchByColumn = exports.transSearchByColumn = function transSearchByColumn(params) {
  var transOptionName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'orders';
  var paramsKeys = _objectSpread({}, params);
  var paramOrders = params[transOptionName || 'orders'] || {};
  var orders = [];
  Object.keys(paramOrders).forEach(function (oItem) {
    orders.push({
      column: oItem,
      asc: paramOrders[oItem] === 'ascend'
    });
  });
  paramsKeys[transOptionName || 'orders'] = orders.length ? orders : undefined;
  return paramsKeys;
};