const { ipcMain } = require("electron");
//const { app } = require("electron");
const log = require("electron-log");
//const Nucleus = require("nucleus-nodejs");
const { default: ipcTypes } = require("../src/ipc.types.commonjs");
const amplitude = require('@amplitude/analytics-node');
const { store } = require("./electron-store");
const deviceId = store.get("deviceId");
const { app } = require("electron");

let userId;
amplitude.init('a733ff926aef84f93baf95e66b5dcb75');
// Nucleus.init("5f91b569b95bac34eefdb63a", {
//   disableInDev: true,
//   debug: false,
//   version: app.getVersion(),
// });

// Nucleus.setProps({
//   version: app.getVersion(),
// });

// Nucleus.onError = (type, err) => {
//   log.error(err);
//   // type will either be uncaughtException, unhandledRejection or windowError
// };

ipcMain.on(ipcTypes.app.toMain.setUserName, (event, userid) => {
  userId = userid;
});

ipcMain.on(ipcTypes.app.toMain.track, (e, args) => {
   log.log("Analytics Event", args);
  const { event, ...eventDetails } = args;
  try {
    ////  Nucleus.track(event, eventDetails);
    amplitude.track(event, eventDetails, { device_id: deviceId, user_id: userId, app_version: app.getVersion(), });
  } catch (error) {
    log.error(error);
  }
});
