import { MONTHS } from '../config.js'; export class Countdown { constructor(container) { this.container = container; this.nextEvent = null; this.intervalId = null; } setNextEvent(event) { this.nextEvent = event; this.render(); this.startTicking(); } startTicking() { if (this.intervalId) { clearInterval(this.intervalId); } this.intervalId = setInterval(() => this.updateTime(), 1000); } getTimeUntil(date) { const now = new Date(); const target = new Date(date); target.setHours(14, 0, 0, 0); // Assume 14:00 start time const diff = target - now; if (diff <= 0) { return { days: 0, hours: 0, minutes: 0, seconds: 0, passed: true }; } const days = Math.floor(diff / (1000 * 60 * 60 * 24)); const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); const seconds = Math.floor((diff % (1000 * 60)) / 1000); return { days, hours, minutes, seconds, passed: false }; } render() { if (!this.nextEvent) { this.container.innerHTML = ''; return; } const date = new Date(this.nextEvent.date); const formattedDate = `${date.getDate()} ${MONTHS[date.getMonth()]}`; this.container.innerHTML = `