2024-12-23 19:13:36 +00:00
|
|
|
"use client";
|
|
|
|
|
import { calculateTimeLeft } from "@/lib/hooks/useCalculateTimeLeft";
|
2025-02-08 09:02:21 +00:00
|
|
|
import { useLotteryStatus } from "@/store/store";
|
2024-12-23 19:13:36 +00:00
|
|
|
import React, { useState, useEffect, Dispatch, SetStateAction } from "react";
|
2024-11-25 09:34:54 +00:00
|
|
|
|
|
|
|
|
interface LotteryCountDownProps {
|
2024-12-09 13:35:43 +00:00
|
|
|
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
|
2025-02-08 09:02:21 +00:00
|
|
|
lotteryStatus: "Upcoming" | "Ongoing" | "Finished";
|
2024-11-25 09:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-09 13:35:43 +00:00
|
|
|
const LotteryCountDown: React.FC<LotteryCountDownProps> = ({
|
|
|
|
|
startDate,
|
|
|
|
|
endDate,
|
|
|
|
|
lotteryStatus,
|
|
|
|
|
}) => {
|
2024-11-25 09:34:54 +00:00
|
|
|
const [timeLeft, setTimeLeft] = useState({
|
|
|
|
|
hours: 0,
|
|
|
|
|
minutes: 0,
|
|
|
|
|
seconds: 0,
|
|
|
|
|
});
|
2025-02-08 09:02:21 +00:00
|
|
|
const { status, setStatus } = useLotteryStatus();
|
2024-12-29 18:02:23 +00:00
|
|
|
|
2024-11-25 09:34:54 +00:00
|
|
|
useEffect(() => {
|
2025-02-08 09:02:21 +00:00
|
|
|
setStatus(lotteryStatus);
|
|
|
|
|
|
2024-11-25 09:34:54 +00:00
|
|
|
const timer = setInterval(() => {
|
2025-02-08 09:02:21 +00:00
|
|
|
if (lotteryStatus === "Upcoming") {
|
2024-12-09 13:35:43 +00:00
|
|
|
const timeToStart = calculateTimeLeft(startDate);
|
|
|
|
|
setTimeLeft(timeToStart);
|
|
|
|
|
|
2024-12-23 19:13:36 +00:00
|
|
|
if (
|
|
|
|
|
timeToStart.hours === 0 &&
|
|
|
|
|
timeToStart.minutes === 0 &&
|
|
|
|
|
timeToStart.seconds === 0
|
|
|
|
|
) {
|
2025-02-08 09:02:21 +00:00
|
|
|
setStatus("Ongoing"); // Update status to "started"
|
2024-12-09 13:35:43 +00:00
|
|
|
}
|
2025-02-08 09:02:21 +00:00
|
|
|
} else if (lotteryStatus === "Ongoing") {
|
2024-12-09 13:35:43 +00:00
|
|
|
const timeToEnd = calculateTimeLeft(endDate);
|
|
|
|
|
setTimeLeft(timeToEnd);
|
|
|
|
|
|
2024-12-23 19:13:36 +00:00
|
|
|
if (
|
|
|
|
|
timeToEnd.hours === 0 &&
|
|
|
|
|
timeToEnd.minutes === 0 &&
|
|
|
|
|
timeToEnd.seconds === 0
|
|
|
|
|
) {
|
2025-02-08 09:02:21 +00:00
|
|
|
setStatus("Finished"); // Update status to "finished"
|
2024-12-09 13:35:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-11-25 09:34:54 +00:00
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
|
|
return () => clearInterval(timer); // Clean up interval on component unmount
|
2025-02-08 09:02:21 +00:00
|
|
|
}, [startDate, endDate, lotteryStatus]);
|
2024-11-25 09:34:54 +00:00
|
|
|
|
|
|
|
|
return (
|
2024-12-29 18:02:23 +00:00
|
|
|
<div className="bg-lightPrimaryContainer sm:p-6 py-3 flex flex-col w-full md:gap-2 rounded-[12px] sm:gap-3 gap-0 text-lightOnPrimaryContainer">
|
|
|
|
|
<h3 className="text-center md:font-heading-1-regular sm:text-[32px] sm:leading-[40px] text-[20px] leading-[28px] text-lightOnSurface">
|
2025-02-08 09:02:21 +00:00
|
|
|
{status === "Ongoing"
|
2024-12-23 19:13:36 +00:00
|
|
|
? "Bije dowam edýär"
|
2025-02-08 09:02:21 +00:00
|
|
|
: status === "Finished"
|
2024-12-23 19:13:36 +00:00
|
|
|
? "Bije tamamlandy"
|
|
|
|
|
: "Bije"}
|
2024-12-11 13:14:14 +00:00
|
|
|
</h3>
|
2024-11-25 09:34:54 +00:00
|
|
|
{/* LotteryCountDown */}
|
2025-02-08 09:02:21 +00:00
|
|
|
{status === "Upcoming" && (
|
2024-12-11 13:14:14 +00:00
|
|
|
<div className="flex items-center sm:gap-6 gap-2 justify-between">
|
2024-12-29 18:02:23 +00:00
|
|
|
<div className="flex flex-col items-center justify-center flex-1 sm:p-6 p-4 sm:pb-3">
|
2024-12-11 13:14:14 +00:00
|
|
|
<h3 className="md:text-[80px] sm:text-[56px] text-[28px] md:leading-[88px] sm:leading-[64px] leading-[36px] -tracking-[1%]">
|
|
|
|
|
{timeLeft.hours}
|
|
|
|
|
</h3>
|
|
|
|
|
<h4 className="font-medium md:text-[20px] sm:text-[18px] text-[14px] sm:leading-[28px] leading-[20px] -tracking-[1%] text-lightOnSurfaceVariant">
|
2025-02-08 09:02:21 +00:00
|
|
|
sagat
|
2024-12-11 13:14:14 +00:00
|
|
|
</h4>
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-12-29 18:02:23 +00:00
|
|
|
{/* Dots */}
|
|
|
|
|
<div className="flex flex-col sm:gap-3 gap-2">
|
|
|
|
|
<div className="sm:w-3 sm:h-3 w-1 h-1 rounded-full bg-lightOnSurfaceVariant"></div>
|
|
|
|
|
<div className="sm:w-3 sm:h-3 w-1 h-1 rounded-full bg-lightOnSurfaceVariant"></div>
|
2024-12-11 13:14:14 +00:00
|
|
|
</div>
|
|
|
|
|
|
2024-12-29 18:02:23 +00:00
|
|
|
<div className="flex flex-col items-center justify-center flex-1 sm:p-6 p-4 sm:pb-3">
|
2024-12-11 13:14:14 +00:00
|
|
|
<h3 className="md:text-[80px] sm:text-[56px] text-[28px] md:leading-[88px] sm:leading-[64px] leading-[36px] -tracking-[1%]">
|
|
|
|
|
{timeLeft.minutes}
|
|
|
|
|
</h3>
|
|
|
|
|
<h4 className="font-medium md:text-[20px] sm:text-[18px] text-[14px] sm:leading-[28px] leading-[20px] -tracking-[1%] text-lightOnSurfaceVariant">
|
2025-02-08 09:02:21 +00:00
|
|
|
minut
|
2024-12-11 13:14:14 +00:00
|
|
|
</h4>
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-12-29 18:02:23 +00:00
|
|
|
{/* Dots */}
|
|
|
|
|
<div className="flex flex-col sm:gap-3 gap-2">
|
|
|
|
|
<div className="sm:w-3 sm:h-3 w-1 h-1 rounded-full bg-lightOnSurfaceVariant"></div>
|
|
|
|
|
<div className="sm:w-3 sm:h-3 w-1 h-1 rounded-full bg-lightOnSurfaceVariant"></div>
|
2024-12-11 13:14:14 +00:00
|
|
|
</div>
|
|
|
|
|
|
2024-12-29 18:02:23 +00:00
|
|
|
<div className="flex flex-col items-center justify-center flex-1 sm:p-6 p-4 sm:pb-3">
|
2024-12-11 13:14:14 +00:00
|
|
|
<h3 className="md:text-[80px] sm:text-[56px] text-[28px] md:leading-[88px] sm:leading-[64px] leading-[36px] -tracking-[1%]">
|
|
|
|
|
{timeLeft.seconds}
|
|
|
|
|
</h3>
|
|
|
|
|
<h4 className="font-medium md:text-[20px] sm:text-[18px] text-[14px] sm:leading-[28px] leading-[20px] -tracking-[1%] text-lightOnSurfaceVariant">
|
2025-02-08 09:02:21 +00:00
|
|
|
sekunt
|
2024-12-11 13:14:14 +00:00
|
|
|
</h4>
|
|
|
|
|
</div>
|
2024-11-25 09:34:54 +00:00
|
|
|
</div>
|
2024-12-11 13:14:14 +00:00
|
|
|
)}
|
2024-12-09 13:35:43 +00:00
|
|
|
|
|
|
|
|
<div className="flex items-center justify-center text-lightOnSurfaceVariant md:font-heading-1-regular md:text-[20px] sm:text-[18px] sm:leading-[28px] text-[14px] leading-[20px]">
|
|
|
|
|
<span>
|
2025-02-08 09:02:21 +00:00
|
|
|
{status === "Upcoming"
|
2024-12-23 19:13:36 +00:00
|
|
|
? "- den başlar"
|
2025-02-08 09:02:21 +00:00
|
|
|
: status === "Ongoing"
|
2024-12-23 19:13:36 +00:00
|
|
|
? "girmek üçin aşakda kodyňyzy giriziň"
|
|
|
|
|
: "netijeleri görmek üçin aşakda kodyňyzy giriziň"}
|
2024-12-09 13:35:43 +00:00
|
|
|
</span>
|
2024-11-25 09:34:54 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default LotteryCountDown;
|