import { useCallback, useEffect, useRef, useState } from "react"; import { fetchInboxLanes, type InboxLanes } from "@/lib/inbox-api"; /** Default poll interval. Tail-integration (T19) will replace this. */ const POLL_INTERVAL_MS = 5_000; export function useInboxLanes() { const [lanes, setLanes] = useState({ rejected: [], candidates: [], unmatched: [], done_today: [], }); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const pollRef = useRef | null>(null); const refetch = useCallback(async () => { try { const next = await fetchInboxLanes(); setLanes(next); setError(null); } catch (e) { setError(e as Error); } finally { setLoading(false); } }, []); useEffect(() => { void refetch(); pollRef.current = setInterval(() => { void refetch(); }, POLL_INTERVAL_MS); return () => { if (pollRef.current) clearInterval(pollRef.current); }; }, [refetch]); return { lanes, loading, error, refetch }; }