/*
 * @Author:
 * @Date: 2023-12-28 18:10:02
 * @LastEditors:
 * @LastEditTime: 2024-03-13 14:44:25
 * @Description: kxs files
 * @filePath:
 */
import Cookies from "./cookie";
import { ShakeDownEncrypt, ShakeDownDecrypt } from "./CryptoJS";

var PublicLib = {
  putCookieInfo: function (option, val) {
    let Key,
      Value,
      Type = 1,
      Conf;
    if (!option.Key) {
      Key = option;
      Value = val;
    } else {
      Key = option.Key;
      Value = option.Value;
      Type = option.Type;
      Conf = option.Conf;
    }
    Cookies.set(Key, ShakeDownEncrypt(JSON.stringify(Value)), Type, Conf);
  },

  getCookieInfo: function (option) {
    let Key, Type, Conf;
    if (!option.Key) {
      Key = option;
    } else {
      Key = option.Key;
      Type = option.Type;
      Conf = option.Conf;
    }
    if (Type == 3) {
      return new Promise(async (resolve, reject) => {
        resolve(
          JSON.parse(ShakeDownDecrypt(await Cookies.get(Key, Type, Conf)))
        );
      });
    } else {
      return JSON.parse(ShakeDownDecrypt(Cookies.get(Key, Type, Conf)));
    }
  }
};
export default PublicLib;
