document.addEventListener('DOMContentLoaded', function() { let gamesData = []; // To store games data for CSV export const playerDetailContainer = document.getElementById('player-detail-container'); const authLinks = document.getElementById('auth-links'); // --- Auth Logic --- const updateAuthUI = (user) => { if (user) { authLinks.innerHTML = ` `; document.getElementById('logout-btn').addEventListener('click', logout); } else { authLinks.innerHTML = ` Login Register `; } }; const logout = () => { fetch('/api/logout.php').then(() => window.location.href = '/'); }; const checkSession = () => { fetch('/api/check_session.php') .then(response => response.json()) .then(data => { updateAuthUI(data.loggedIn ? data.user : null); }); }; // --- Player Detail Logic --- const renderPlayerDetails = (playerData) => { const details = playerData.details; gamesData = playerData.recent_games; // Store for export let biographyHtml = `
${details.strTeam}
${details.strDescriptionEN || 'No biography available.'}
Position: ${details.strPosition}
Height: ${details.strHeight}
Weight: ${details.strWeight}
Nationality: ${details.strNationality}
Date of Birth: ${details.dateBorn}
Sport: ${details.strSport}
| Date | Event | Home Team | Away Team | Score |
|---|---|---|---|---|
| ${game.dateEvent} | ${game.strEvent} | ${game.strHomeTeam} | ${game.strAwayTeam} | ${game.intHomeScore} - ${game.intAwayScore} |