/** * Next Match Panel Component * Displays countdown timer, matchup analysis, and weather details. */ import { setHTML } from '../utils/dom.js'; import { Toast } from './Toast.js'; export class NextMatchPanel { constructor(containerEl) { this.containerEl = containerEl; this.timerInterval = null; } render() { if (!this.containerEl) return; setHTML(this.containerEl, `
`); this._startTimer(); this.containerEl.querySelector('#btn-notify-match')?.addEventListener('click', () => { Toast.show({ message: 'Notification reminder set for Manchester United vs Liverpool clash!', type: 'success', duration: 4000 }); }); } _startTimer() { const timerEl = this.containerEl.querySelector('#next-match-countdown'); if (!timerEl) return; // Set countdown to 1 day, 6 hours from now const targetDate = new Date(Date.now() + 24 * 60 * 60 * 1000 + 6 * 60 * 60 * 1000).getTime(); const updateTimer = () => { const now = Date.now(); const diff = targetDate - now; if (diff <= 0) { timerEl.textContent = 'MATCH LIVE'; clearInterval(this.timerInterval); return; } const days = Math.floor(diff / (1000 * 60 * 60 * 24)); const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); const mins = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); const secs = Math.floor((diff % (1000 * 60)) / 1000); timerEl.textContent = `${days}d ${hours.toString().padStart(2, '0')}h ${mins.toString().padStart(2, '0')}m ${secs.toString().padStart(2, '0')}s`; }; updateTimer(); this.timerInterval = setInterval(updateTimer, 1000); } destroy() { if (this.timerInterval) { clearInterval(this.timerInterval); } } }