"use client"; import { useState, useEffect } from "react"; const COOLING_HOURS = 72; const COOLING_MS = COOLING_HOURS * 60 * 60 * 1000; export interface CountdownResult { hours: number; minutes: number; seconds: number; isExpired: boolean; display: string; } export function useCountdown(createdAt: string): CountdownResult { const [now, setNow] = useState(Date.now()); useEffect(() => { const timer = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(timer); }, []); const created = new Date(createdAt).getTime(); const deadline = created + COOLING_MS; const remaining = Math.max(0, deadline - now); const totalSeconds = Math.floor(remaining / 1000); const hours = Math.floor(totalSeconds / 3600); const minutes = Math.floor((totalSeconds % 3600) / 60); const seconds = totalSeconds % 60; const pad = (n: number) => n.toString().padStart(2, "0"); const display = `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`; return { hours, minutes, seconds, isExpired: remaining === 0, display, }; }