"use client"; import { calculateTimeLeft } from "@/lib/hooks/useCalculateTimeLeft"; import { useLotteryStatus } from "@/store/store"; import React, { useState, useEffect, Dispatch, SetStateAction } from "react"; interface LotteryCountDownProps { startDate: string; // Event start date in "YYYY-MM-DD HH:mm:ss" format endDate: string; // Event end date in "YYYY-MM-DD HH:mm:ss" format lotteryStatus: "Upcoming" | "Ongoing" | "Finished"; } const LotteryCountDown: React.FC = ({ startDate, endDate, lotteryStatus, }) => { const [timeLeft, setTimeLeft] = useState({ hours: 0, minutes: 0, seconds: 0, }); const { status, setStatus } = useLotteryStatus(); useEffect(() => { setStatus(lotteryStatus); const timer = setInterval(() => { if (lotteryStatus === "Upcoming") { const timeToStart = calculateTimeLeft(startDate); setTimeLeft(timeToStart); if ( timeToStart.hours === 0 && timeToStart.minutes === 0 && timeToStart.seconds === 0 ) { setStatus("Ongoing"); // Update status to "started" } } else if (lotteryStatus === "Ongoing") { const timeToEnd = calculateTimeLeft(endDate); setTimeLeft(timeToEnd); if ( timeToEnd.hours === 0 && timeToEnd.minutes === 0 && timeToEnd.seconds === 0 ) { setStatus("Finished"); // Update status to "finished" } } }, 1000); return () => clearInterval(timer); // Clean up interval on component unmount }, [startDate, endDate, lotteryStatus]); return (

{status === "Ongoing" ? "Çeklis dowam edýär" : status === "Finished" ? "Çeklisx tamamlandy" : null}

{/* LotteryCountDown */} {status === "Upcoming" && (

{timeLeft.hours}

{/* Dots */}

{timeLeft.minutes}

{/* Dots */}

{timeLeft.seconds}

)}
); }; export default LotteryCountDown;