"use client"; import { useEffect, useState } from "react"; type RemainingTime = { hours: number; minutes: number; seconds: number; }; function getRemainingTime(): RemainingTime { const now = new Date(); const endOfDay = new Date(now); endOfDay.setHours(23, 59, 59, 999); const totalSeconds = Math.max(0, Math.floor((endOfDay.getTime() - now.getTime()) / 1000)); return { hours: Math.floor(totalSeconds / 3600), minutes: Math.floor((totalSeconds % 3600) / 60), seconds: totalSeconds % 60, }; } function TimeBox({ value, label }: { value: number; label: string }) { return (
{String(value).padStart(2, "0")} {label}
); } export function SpecialSaleCountdown() { const [remaining, setRemaining] = useState(getRemainingTime); useEffect(() => { const timer = window.setInterval(() => setRemaining(getRemainingTime()), 1000); return () => window.clearInterval(timer); }, []); return (
); }