import dayjs from 'dayjs';
import { AdEngine } from './AdEngine';
export 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.instance.getAdFrequencyByPlacement(placement);
    if (adFrequency == null || adFrequency.type !== 'time-window') {
      return 0;
    }
    return adFrequency.value;
  }
  getCurrentWindowKey(placement) {
    const today = dayjs();
    const minuteSinceStartOfADay = today.startOf('day').diff(today, 'minute');
    const windowIndex = Math.ceil(minuteSinceStartOfADay / this.getTimeWindowSettings(placement));
    return `${today.format('DD-MM-YYYY')}-${windowIndex}`;
  }
}
//# sourceMappingURL=TimeWindowTracker.js.map