import { useState, useEffect } from 'react'; import { ref, onValue } from 'firebase/database'; import { db } from '../lib/firebase'; import type { Match } from '../types/database'; import { Loader2, Zap, Timer } from 'lucide-react'; import { Link } from 'react-router-dom'; const LiveGames = () => { const [liveMatches, setLiveMatches] = useState<(Match & { escalao: string, jornadaId: string })[]>([]); const [loading, setLoading] = useState(true); useEffect(() => { const jornadasRef = ref(db, 'jornadas'); const unsubscribe = onValue(jornadasRef, (snapshot) => { const data = snapshot.val(); const allLive: (Match & { escalao: string, jornadaId: string })[] = []; if (data) { Object.entries(data).forEach(([escalao, jornadas]: [string, any]) => { if (!Array.isArray(jornadas)) return; jornadas.forEach((jornadaData, jornadaIdx) => { if (!jornadaData) return; Object.entries(jornadaData).forEach(([matchId, match]: [string, any]) => { if (match.isLive) { allLive.push({ id: matchId, ...match, escalao, jornadaId: jornadaIdx.toString() }); } }); }); }); } setLiveMatches(allLive); setLoading(false); }); return () => unsubscribe(); }, []); return (

Jogos em Direto

Jogos a decorrer neste momento.

{loading ? (

A procurar jogos em direto...

) : liveMatches.length === 0 ? (

Sem jogos em direto

Não existem jogos marcados como "Em Direto" neste momento. Vai às Jornadas para iniciar um acompanhamento em tempo real.

IR PARA JORNADAS
) : (
{liveMatches.map((match) => (
{match.escalao} - Jornada {match.jornadaId}
Direto
{match.home_nome}
{match.home_golos} : {match.away_golos}
{match.away_nome}
))}
)}
); }; export default LiveGames;