import { getBAEventParameters } from "@elliemae/pui-analytics-so";
import { getProductAppDetails } from "./helpers.js";
let gLogRocket = null;
const getLogRocket = () => gLogRocket;
const setLogRocket = (logrocket) => {
  gLogRocket = logrocket || null;
};
const cleanupData = (data) => {
  const cleanedData = {};
  Object.entries(data).forEach(([key, value]) => {
    cleanedData[key] = value === void 0 || value === null ? "" : value;
  });
  return cleanedData;
};
const getEventData = (eventEx) => {
  const eventData = {
    ...eventEx,
    ...getBAEventParameters(),
    ...getProductAppDetails()
  };
  return cleanupData(eventData);
};
const lrTrack = (event, eventEx = {}) => {
  const logRocket = getLogRocket();
  if (logRocket) {
    logRocket.track(event, getEventData(eventEx));
  }
};
const lrIdentify = (userId, eventEx) => {
  const logRocket = getLogRocket();
  if (logRocket) {
    logRocket.identify(userId, cleanupData(eventEx));
  }
};
export {
  getLogRocket,
  lrIdentify,
  lrTrack,
  setLogRocket
};
