"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TimeWindowTracker = void 0;
var _dayjs = _interopRequireDefault(require("dayjs"));
var _AdEngine = require("./AdEngine");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
class TimeWindowTracker {
  #markedTimeWindow;
  static #instance;
  constructor() {
    this.#markedTimeWindow = new Map();
  }
  static get instance() {
    if (!TimeWindowTracker.#instance) {
      TimeWindowTracker.#instance = new TimeWindowTracker();
    }
    return TimeWindowTracker.#instance;
  }
  clear() {
    this.#markedTimeWindow.clear();
  }
  hasReachedLimit(placement) {
    const currentWindowKey = this.getCurrentWindowKey(placement);
    return this.#markedTimeWindow.get(placement) === currentWindowKey;
  }
  markSeen(placement) {
    this.#markedTimeWindow.set(placement, this.getCurrentWindowKey(placement));
  }
  getTimeWindowSettings(placement) {
    const adFrequency = _AdEngine.AdEngine.instance.getAdFrequencyByPlacement(placement);
    if (adFrequency == null || adFrequency.type !== 'time-window') {
      return 0;
    }
    return adFrequency.value;
  }
  getCurrentWindowKey(placement) {
    const today = (0, _dayjs.default)();
    const minuteSinceStartOfADay = today.startOf('day').diff(today, 'minute');
    const windowIndex = Math.ceil(minuteSinceStartOfADay / this.getTimeWindowSettings(placement));
    return `${today.format('DD-MM-YYYY')}-${windowIndex}`;
  }
}
exports.TimeWindowTracker = TimeWindowTracker;
//# sourceMappingURL=TimeWindowTracker.js.map