import { JSEncrypt } from 'jsencrypt'
import { md5 } from 'js-md5'
export const setProperty = (prop: string, val: any, dom = document.documentElement) => {
    dom.style.setProperty(prop, val);
};

export const mix = (color1: string, color2: string, weight: number = 0.5): string => {
    let color = '#';
    for (let i = 0; i <= 2; i++) {
        const c1 = parseInt(color1.substring(1 + i * 2, 3 + i * 2), 16);
        const c2 = parseInt(color2.substring(1 + i * 2, 3 + i * 2), 16);
        const c = Math.round(c1 * weight + c2 * (1 - weight));
        color += c.toString(16).padStart(2, '0');
    }
    return color;
};
export const encryptedData =  (data: any) => {
  // 创建一个 JSEncrypt 实例
  let encrypt = new JSEncrypt();
  
  // 设置公钥
  encrypt.setPublicKey('MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDB+o3BYY2/kxg1zjIGmZjNJCc3pdXXv927rAvmDSrTVTdYJ1uTYpnjw4tcUYgX5ABD3LzPZMDhJVT7DMOsb7UEl0sx30m6ZFBGrgrbxhm7t8/Ep1yWT41jgo/BYLOa6zWXBHbMxr12/LEep7SjHngY5QzSF/EuQ6H68xguRaAOXwIDAQAB');
  
  // 加密数据
  let result = encrypt.encrypt(data);
  
  return result;
};
export const md5Data = (data: any) => {
  console.log('Data type:', typeof data); // 打印输入数据类型
  const stringData = typeof data === 'string' ? data : JSON.stringify(data);
  return md5(stringData);
};

