'use client' import { useEffect, useState } from "react" const msInSecond = 1000 const msInMinute = 60 * msInSecond const msInHour = 60 * msInMinute const msInDay = 24 * msInHour const getPartsOfTimeDuration = (duration: number) => { const days = Math.floor(duration / msInDay) const hours = Math.floor((duration % msInDay) / msInHour) const minutes = Math.floor((duration % msInHour) / msInMinute) const seconds = Math.floor((duration % msInMinute) / msInSecond) return { days, hours, minutes, seconds } } export default function Countdown({ style }: any) { const [timeDif, setTimeDif] = useState(() => { const now = Date.now() const endDateTime = new Date() endDateTime.setDate(endDateTime.getDate() + 2) // Set end date 2 days from now return endDateTime.getTime() - now }) useEffect(() => { const interval = setInterval(() => { setTimeDif((prev) => { const updatedTime = prev - 1000 if (updatedTime <= 0) { clearInterval(interval) return 0 } return updatedTime }) }, 1000) return () => clearInterval(interval) }, []) const timeParts = getPartsOfTimeDuration(timeDif) return ( <> {!style && <>
{timeParts.days}
Days
{timeParts.hours}
Hours
{timeParts.minutes}
Minutes
{timeParts.seconds}
Seconds
} {style === 1 && <>
{timeParts.days} DAYS
{timeParts.hours} Hours
{timeParts.minutes} Minutes
{timeParts.seconds} Seconds
} {style === 2 && <>

{timeParts.days} DAYS

{timeParts.hours} Hours

{timeParts.minutes}Minutes

{timeParts.seconds}Seconds

} {style === 3 && <>
{timeParts.days} DAYS
{timeParts.hours} Hours
{timeParts.minutes} Minutes
{timeParts.seconds} Seconds
} ) }