import React, { useState } from 'react'; import { doc, updateDoc, increment } from 'firebase/firestore'; import { db, handleFirestoreError, OperationType } from '../firebase'; import { CyberMatch } from '../types'; import { Calendar, Clock, Trophy, Flame, CheckCircle, ChevronRight, Vote, Sparkles } from 'lucide-react'; import { Language } from '../translations'; interface GamesViewProps { cyberMatches: CyberMatch[]; currentLanguage: Language; } export const GamesView: React.FC = ({ cyberMatches, currentLanguage }) => { const [selectedGameFilter, setSelectedGameFilter] = useState('all'); const [votedMatchIds, setVotedMatchIds] = useState(() => { try { const saved = localStorage.getItem('nova_voted_matches'); return saved ? JSON.parse(saved) : []; } catch { return []; } }); // Localized UI strings const localDict = { EN: { title: "🎮 Cyber Match Schedule", subtitle: "Track live and upcoming professional matches, vote for your favorite squad, and watch the win probability rise in real-time!", allGames: "All Games", upcomingTab: "Upcoming", liveTab: "Live Now", finishedTab: "Completed", voteForA: "Vote Team A", voteForB: "Vote Team B", totalVotes: "Total Votes", winRateLabel: "Win Probability", noMatches: "No matches scheduled at the moment. Admins can create new matches in the Control Board!", votedMessage: "Your vote has been counted!", timeLabel: "Match Date & Time", vsLabel: "VS", popularVote: "Popular Choice" }, UZ: { title: "🎮 O'yinlar O'tkaziladigan Taqvim", subtitle: "Professional va jonli o'yinlar jadvalini kuzatib boring, sevimli jamoangizga ovoz bering va ularning g'alaba qozonish imkoniyatini real vaqtda oshiring!", allGames: "Barcha O'yinlar", upcomingTab: "Kutilayotgan", liveTab: "Jonli Efir", finishedTab: "Yakunlangan", voteForA: "A Jamoaga Ovoz Berish", voteForB: "B Jamoaga Ovoz Berish", totalVotes: "Umumiy Ovozlar", winRateLabel: "G'alaba Imkoniyati", noMatches: "Hozircha hech qanday o'yin rejalashtirilmagan. Adminlar Boshqaruv Panelida yangi o'yinlar qo'shishlari mumkin!", votedMessage: "Ovozingiz qabul qilindi!", timeLabel: "O'yin Kuni va Vaqti", vsLabel: "VS", popularVote: "Ko'pchilik Tanlovi" }, RU: { title: "🎮 Расписание Кибер-Матчей", subtitle: "Следите за профессиональными матчами в прямом эфире и расписанием, голосуйте за свои команды и наблюдайте за ростом шансов на победу в реальном времени!", allGames: "Все Игры", upcomingTab: "Ожидаемые", liveTab: "Прямой Эфир", finishedTab: "Завершенные", voteForA: "Голосовать за команду А", voteForB: "Голосовать за команду Б", totalVotes: "Всего Голосов", winRateLabel: "Вероятность Победы", noMatches: "На данный момент матчей не запланировано. Администраторы могут создать новые матчи в Панели Управления!", votedMessage: "Ваш голос учтен!", timeLabel: "Дата и Время Матча", vsLabel: "VS", popularVote: "Выбор большинства" } }; const ui = localDict[currentLanguage] || localDict['EN']; // Handle voting logic const handleVote = async (matchId: string, team: 'teamA' | 'teamB') => { try { const matchRef = doc(db, 'cyber_matches', matchId); const updateData = team === 'teamA' ? { 'teamA.votes': increment(1) } : { 'teamB.votes': increment(1) }; await updateDoc(matchRef, updateData); const newVoted = [...votedMatchIds, `${matchId}-${team}`]; setVotedMatchIds(newVoted); localStorage.setItem('nova_voted_matches', JSON.stringify(newVoted)); } catch (err) { handleFirestoreError(err, OperationType.UPDATE, `cyber_matches/${matchId}`); } }; // Get game list for filtering const gamesList: string[] = Array.from(new Set(cyberMatches.map(m => m.gameName as string))).filter(Boolean) as string[]; // Filtered matches const filteredMatches = cyberMatches.filter(m => { if (selectedGameFilter === 'all') return true; return m.gameName.toLowerCase() === selectedGameFilter.toLowerCase(); }); return (
{/* Header and intro banner */}
Live Tournament Taqvim & Predictor

{ui.title}

{ui.subtitle}

{/* Game Filters Section */}
{gamesList.map((g) => ( ))}
{/* Calendar Matches Grid */} {filteredMatches.length === 0 ? (

{ui.vsLabel} NO EVENT SCHEDULED

{ui.noMatches}

) : (
{filteredMatches.map((match) => { const votesA = match.teamA.votes || 0; const votesB = match.teamB.votes || 0; const total = votesA + votesB; const percentA = total > 0 ? Math.round((votesA / total) * 100) : 50; const percentB = total > 0 ? Math.round((votesB / total) * 100) : 50; const hasVotedA = votedMatchIds.includes(`${match.id}-teamA`); const hasVotedB = votedMatchIds.includes(`${match.id}-teamB`); const hasVotedAny = hasVotedA || hasVotedB; return (
{/* Status indicator line on the side */}
{/* Left Section: Metadata */}
{match.status === 'live' && } {match.status === 'live' ? ui.liveTab : match.status === 'finished' ? ui.finishedTab : ui.upcomingTab} {match.gameName}
{match.dateTime.split(' ')[0]}
{match.dateTime.split(' ')[1] || 'TBD'}
{/* Middle Section: Teams & Interactive Voting Arena */}
{/* TEAM A */}
{/* VS SPLITTER */}
{ui.vsLabel}
{/* TEAM B */}
{/* Right Section: Win Percentage Bar & Total votes */}
{ui.winRateLabel} {percentA}% vs {percentB}%
{/* Dual ProgressBar */}
{ui.totalVotes}: {total}
{hasVotedAny && (
{ui.votedMessage}
)}
); })}
)}
); };