"use strict";
const common_vendor = require("../common/vendor.js");
const utils_cryptoJs_min = require("./crypto-js.min.js");
let loading = false;
let count = 0;
const showLoading = function(title = "") {
  if (!loading) {
    common_vendor.index.showLoading({
      title: title || "",
      mask: true
    });
    loading = true;
  }
  count += 1;
};
const hideLoading = function() {
  let timer = setTimeout(() => {
    if (count === 1 && loading) {
      common_vendor.index.hideLoading();
      loading = false;
    }
    count -= 1;
    clearTimeout(timer);
    timer = null;
  }, 0);
};
const showToast = function(msg, fn = () => {
}, duration = 1500) {
  common_vendor.index.showToast({
    title: msg,
    mask: true,
    icon: "none",
    duration
  });
  if (fn) {
    setTimeout(() => {
      fn();
    }, duration);
  }
};
const showModal = function(content, callBack = () => {
}, data = {}) {
  common_vendor.index.showModal({
    content,
    title: data.title || "",
    confirmText: data.confirmText || "确定",
    confirmColor: data.confirmColor || "",
    cancelColor: data.cancelColor || "",
    cancelText: data.cancelText || "",
    showCancel: data.cancelText ? true : false,
    success: (res) => {
      if (res.confirm && callBack instanceof Function) {
        callBack();
      }
      if (!res.confirm && data.callBack instanceof Function) {
        data.callBack();
      }
    }
  });
};
const isEmpty = function(obj) {
  if (obj == void 0 || obj == null || obj == "") {
    return true;
  } else if (obj instanceof Array) {
    return obj.length <= 0;
  } else if (obj instanceof Object) {
    return Object.keys(obj).length <= 0;
  }
  return false;
};
const isNotEmpty = function(obj) {
  return !isEmpty(obj);
};
const desEncrypt = function(message, key) {
  let keyHex = utils_cryptoJs_min.CryptoJS.enc.Utf8.parse(key);
  let encrypted = utils_cryptoJs_min.CryptoJS.DES.encrypt(message, keyHex, {
    mode: utils_cryptoJs_min.CryptoJS.mode.ECB,
    padding: utils_cryptoJs_min.CryptoJS.pad.Pkcs7
  });
  return encrypted.toString();
};
const desDecrypt = function(str, key, exportType) {
  let keyHex = utils_cryptoJs_min.CryptoJS.enc.Utf8.parse(key);
  let decrypted = utils_cryptoJs_min.CryptoJS.DES.decrypt(
    exportType == "hex" ? {
      ciphertext: utils_cryptoJs_min.CryptoJS.enc.Hex.parse(str)
    } : str,
    keyHex,
    {
      mode: utils_cryptoJs_min.CryptoJS.mode.ECB,
      padding: utils_cryptoJs_min.CryptoJS.pad.Pkcs7
    }
  );
  return decrypted.toString(utils_cryptoJs_min.CryptoJS.enc.Utf8);
};
const turnToMap = (list) => {
  let map = {};
  list.map((item) => {
    map[item.routePath] = JSON.parse(item.infoJson || "{}");
  });
  return map;
};
exports.desDecrypt = desDecrypt;
exports.desEncrypt = desEncrypt;
exports.hideLoading = hideLoading;
exports.isEmpty = isEmpty;
exports.isNotEmpty = isNotEmpty;
exports.showLoading = showLoading;
exports.showModal = showModal;
exports.showToast = showToast;
exports.turnToMap = turnToMap;
//# sourceMappingURL=../../.sourcemap/mp-alipay/utils/common.js.map
