"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var customHooks_exports = {};
__export(customHooks_exports, {
  useTrackSessionExpiry: () => useTrackSessionExpiry
});
module.exports = __toCommonJS(customHooks_exports);
var import_react = require("react");
var import_date_fns = require("date-fns");
var import_constants = require("../../../utils/constants.js");
var import_config = require("../../../utils/app-config/config.js");
const useTrackSessionExpiry = (warningNotifiedAt) => {
  const [timeData, setTimeData] = (0, import_react.useState)();
  (0, import_react.useEffect)(() => {
    const timeLeftForExpiryAfterWarning = () => {
      const userWarnInterval = (0, import_config.getAppConfigValue)(
        "sessionTimeoutWarnInterval"
      );
      const userTimeoutInterval = (0, import_config.getAppConfigValue)(
        "sessionTimeoutInterval"
      );
      const warnInterval = userWarnInterval ? parseFloat(userWarnInterval) : import_constants.SESSION_TIMEOUT_INTERVAL.WARN;
      const sessionTimeout = userTimeoutInterval ? parseFloat(userTimeoutInterval) : import_constants.SESSION_TIMEOUT_INTERVAL.EXPIRY;
      const diffTime = sessionTimeout - warnInterval;
      const sessionExpiresIn = warningNotifiedAt + diffTime;
      const seconds = (0, import_date_fns.getSeconds)(sessionExpiresIn - Date.now());
      const minutes = (0, import_date_fns.differenceInMinutes)(sessionExpiresIn, Date.now());
      return {
        seconds: `0${seconds}`.slice(-2),
        minutes: `0${minutes}`.slice(-2)
      };
    };
    const interval = setInterval(() => {
      const { seconds, minutes } = timeLeftForExpiryAfterWarning();
      setTimeData(`${minutes}:${seconds}`);
    }, 1e3);
    return () => {
      clearInterval(interval);
    };
  }, [warningNotifiedAt]);
  return timeData;
};
