import React from 'react'; import { usePollStats } from '../polling/usePollStats'; type EventStatsContextValue = ReturnType & { eventKey: string; slug: string; }; const EventStatsContext = React.createContext(undefined); export function EventStatsProvider({ eventKey, children }: { eventKey: string; children: React.ReactNode }) { const stats = usePollStats(eventKey); const value = React.useMemo( () => ({ eventKey, slug: eventKey, ...stats }), [eventKey, stats.onlineGuests, stats.tasksSolved, stats.latestPhotoAt, stats.loading] ); return {children}; } export function useEventStats() { const ctx = React.useContext(EventStatsContext); if (!ctx) { throw new Error('useEventStats must be used within an EventStatsProvider'); } return ctx; } export function useOptionalEventStats() { return React.useContext(EventStatsContext); }