'use client' import { useEffect, useState } from 'react' export function CountdownTimer({ nextMatch }: { nextMatch: any }) { const [timeLeft, setTimeLeft] = useState({ days: 0, hours: 0, minutes: 0, seconds: 0, }) useEffect(() => { const calculateTimeLeft = () => { const now = new Date() const matchTime = new Date(nextMatch.datetime) const difference = matchTime.getTime() - now.getTime() if (difference <= 0) { return { days: 0, hours: 0, minutes: 0, seconds: 0, } } return { days: Math.floor(difference / (1000 * 60 * 60 * 24)), hours: Math.floor( (difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60) ), minutes: Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60)), seconds: Math.floor((difference % (1000 * 60)) / 1000), } } setTimeLeft(calculateTimeLeft()) const timer = setInterval(() => { setTimeLeft(calculateTimeLeft()) }, 1000) return () => clearInterval(timer) }, [nextMatch]) return (
{[ { value: timeLeft.days, label: 'Days' }, { value: timeLeft.hours, label: 'Hours' }, { value: timeLeft.minutes, label: 'Minutes' }, { value: timeLeft.seconds, label: 'Seconds' }, ].map((item, index) => (
{item.value.toString().padStart(2, '0')} {item.label}
))}
) }