const UserExperior = require("react-native-userexperior");
// import Database from "../../../../../../Components/common/DAsyncStorage";
//
// var vechicleData = Database.get("PIVechicleData");
// var RealmCustomerDetails = Database.get("CustomerDetails");
// let mobileNumber,
//     activityId,
//     activityTypeId,
//     licensePlateNumber,
//     quoteNumber,
//     ncb,
//     name,
//     email;

// activityId = vechicleData[0]?.activityId;
// activityTypeId = vechicleData[0].activityTypeId;
// licensePlateNumber = vechicleData[0]?.licensePlateNumber;
// quoteNumber = vechicleData[0]?.quoteNumber;
// ncb = vechicleData[0]?.ncb;

// mobileNumber = RealmCustomerDetails[0]?.mobileNumber;
// name = RealmCustomerDetails[0]?.name;
// email = RealmCustomerDetails[0]?.email;

const getSubStringObject = (data, type) => {
  if (typeof data === "object") {
    for (let key in data) {
      const str = data[key];
      if (typeof data[key] === "string") {
        if (str.length > 600) {
          data[key] = str.slice(0, 600);
        }
      } else {
        data[key] = str;
      }
    }
  }
  return data;
};

export const UELogEvent = (message, data) => {
  let slicedData = {};
  if (data !== undefined) {
    slicedData = getSubStringObject(data, "event");
  }
  console.log("\n\n");
  console.log("UE Log Event ", message, slicedData);
  console.log("\n\n");

  try {
    UserExperior.logEvent(message, slicedData);
  } catch (error) {
    console.log("Error in LibUserExperior UELogEvent =>", error);
  }
};
export const UELogMessage = (message, data) => {
  let slicedData = {};
  if (data !== undefined) {
    slicedData = getSubStringObject(data, "message");
  }
  console.log("\n\n");
  console.log("UE Log Message ", message, slicedData);
  console.log("\n\n");

  try {
    UserExperior.logMessage(message, slicedData);
  } catch (error) {
    console.log("Error in LibUserExperior UELogMessage =>", error);
  }
};

export const UEStartTimer = UserExperior.startTimer;
export const UEEndTimer = UserExperior.endTimer;
