import { useEffect, useState } from 'react' const CountDown2 = ({ initialTime }) => { const hours = Math.floor(initialTime / 3600) const minutes = Math.floor((initialTime % 3600) / 60) const seconds = initialTime % 60 const [timeLeft, setTimeLeft] = useState({ hour: hours, minute: minutes, second: seconds }) useEffect(() => { const timer = setInterval(() => { const totalSeconds = timeLeft.hour * 3600 + timeLeft.minute * 60 + timeLeft.second const secondsLeft = totalSeconds - 1 if (secondsLeft < 0) { clearInterval(timer) } else { const hours = Math.floor(secondsLeft / 3600) const minutes = Math.floor((secondsLeft % 3600) / 60) const seconds = secondsLeft % 60 setTimeLeft({ hour: hours, minute: minutes, second: seconds }) } }, 1000) return () => clearInterval(timer) }, [timeLeft]) return (