"use client"; import { useEffect, useState } from "react"; /** A countdown in whole seconds, started on demand via `start(seconds)` - * drives the "Resend in Ns" button state after a 429 throttle response. */ export function useCountdown() { const [remaining, setRemaining] = useState(0); useEffect(() => { if (remaining <= 0) return; const timer = setTimeout(() => setRemaining((s) => Math.max(0, s - 1)), 1000); return () => clearTimeout(timer); }, [remaining]); return { remaining, start: (seconds: number) => setRemaining(seconds) }; }