import { useState, useEffect, useCallback } from 'react' import { getSlipQueueCounts } from '@/api/slip-queue' import type { SlipStatus } from '@/api/slip-queue' // Polled independently of whichever tab is open — the badge numbers should // stay live even while looking at a different tab's page. const POLL_INTERVAL_MS = 5000 export function useSlipQueueCounts() { const [counts, setCounts] = useState | null>(null) const refresh = useCallback(async () => { try { const data = await getSlipQueueCounts() setCounts(data) } catch { // Best-effort — badges just keep their last known values on failure. } }, []) useEffect(() => { void refresh() const interval = setInterval(() => { void refresh() }, POLL_INTERVAL_MS) return () => clearInterval(interval) }, [refresh]) return { counts, refresh } }