// app.js

import { smEvent } from "@/api/home.api";
import { encryption } from "@/utils/encrypt";
import config from "@/config";
let SMSdk = {};
// #ifdef MP-WEIXIN
SMSdk = require("../libs/fp-wx.min"); // 设备指纹

// 小程序
SMSdk.initConf({
  organization: "YGXboTJhF42EIELHANew",
  appId: config.SMAPPID,
  publicKey:
    "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCGcxbOln/U2jQ7bUSBz8az3Sh7L+ma/+4dfU0F/2NrMGEu/srWHP/Vnbr6H89jkzDOPBXDXJks4sufNLuwbNMyANyQkvzmcBGv+kueiIoG3tw4aOuCDph62VObTl1sCmu0pbrXZfqDlID+OtgY6QhTRddniXmJ7EHJL3cJHeP6bQIDAQAB",
  apiProtocol: "https",
  authConf: {
    location: false, // 最新的已经不采集位置
  },
});
// #endif

export default {
  SMSdk: SMSdk,
};

export async function smTrackEvent(data) {
  // #ifndef MP-BAIDU
  data.appId = config.SMAPPID;
  const smDeviceId = uni.getStorageSync("smDeviceId");
  if (!smDeviceId) return;
  data.shumeiDeviceId = smDeviceId;
  console.log(data);
  await smEvent(encryption(data));
  // #endif
  return true;
}
