![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.ca/private_html/src/components/ |
import React, { useState, useEffect } from 'react';
import { Clock, AlertTriangle, CheckCircle } from 'lucide-react';
interface CompetitionCountdownProps {
deadline: string;
onEnd?: () => void;
}
export const CompetitionCountdown: React.FC<CompetitionCountdownProps> = ({
deadline,
onEnd
}) => {
const [timeLeft, setTimeLeft] = useState<{
days: number;
hours: number;
minutes: number;
seconds: number;
}>({ days: 0, hours: 0, minutes: 0, seconds: 0 });
const [isEnded, setIsEnded] = useState(false);
const [isEndingSoon, setIsEndingSoon] = useState(false);
useEffect(() => {
const calculateTimeLeft = () => {
const now = new Date().getTime();
const deadlineTime = new Date(deadline).getTime();
const difference = deadlineTime - now;
if (difference <= 0) {
setIsEnded(true);
setTimeLeft({ days: 0, hours: 0, minutes: 0, seconds: 0 });
onEnd?.();
return;
}
const days = Math.floor(difference / (1000 * 60 * 60 * 24));
const hours = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((difference % (1000 * 60)) / 1000);
setTimeLeft({ days, hours, minutes, seconds });
// Check if ending soon (less than 24 hours)
if (difference <= 24 * 60 * 60 * 1000) {
setIsEndingSoon(true);
}
};
calculateTimeLeft();
const timer = setInterval(calculateTimeLeft, 1000);
return () => clearInterval(timer);
}, [deadline, onEnd]);
if (isEnded) {
return (
<div className="flex items-center gap-2 text-red-600 font-medium">
<CheckCircle className="h-4 w-4" />
<span>Competition Ended</span>
</div>
);
}
return (
<div className={`flex items-center gap-2 font-medium ${
isEndingSoon ? 'text-orange-600' : 'text-gray-600'
}`}>
{isEndingSoon ? (
<AlertTriangle className="h-4 w-4" />
) : (
<Clock className="h-4 w-4" />
)}
<span>
{timeLeft.days > 0 && `${timeLeft.days}d `}
{timeLeft.hours.toString().padStart(2, '0')}:
{timeLeft.minutes.toString().padStart(2, '0')}:
{timeLeft.seconds.toString().padStart(2, '0')}
</span>
{isEndingSoon && (
<span className="text-xs bg-orange-100 text-orange-800 px-2 py-1 rounded-full">
Ending Soon!
</span>
)}
</div>
);
};