File size: 42,746 Bytes
7dacdbe 54aa297 7dacdbe 54aa297 7dacdbe 54aa297 7dacdbe 54aa297 7dacdbe | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 | <!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Torneo de Fútbol 2025</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.animate-pulse {
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.live-badge {
box-shadow: 0 0 10px rgba(255, 0, 0, 0.7);
}
.fade-in {
animation: fadeIn 0.5s ease-in;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.player-number {
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
background-color: #3b82f6;
color: white;
font-weight: bold;
margin-right: 8px;
}
</style>
</head>
<body class="bg-gray-100 font-sans">
<div class="container mx-auto px-4 py-8 max-w-6xl">
<!-- Header -->
<header class="mb-10 text-center">
<h1 class="text-4xl md:text-5xl font-bold text-gray-800 mb-2">
<i class="fas fa-trophy text-yellow-500 mr-3"></i>
Torneo de Fútbol 2025
</h1>
<p class="text-lg text-gray-600">Organiza y sigue tu torneo favorito</p>
</header>
<!-- Navigation Tabs -->
<div class="flex border-b border-gray-200 mb-8">
<button id="teams-tab" class="tab-button active px-6 py-3 font-medium text-sm md:text-base rounded-t-lg" data-tab="teams">
<i class="fas fa-users mr-2"></i>Equipos
</button>
<button id="matches-tab" class="tab-button px-6 py-3 font-medium text-sm md:text-base" data-tab="matches">
<i class="fas fa-calendar-alt mr-2"></i>Partidos
</button>
<button id="standings-tab" class="tab-button px-6 py-3 font-medium text-sm md:text-base" data-tab="standings">
<i class="fas fa-table mr-2"></i>Posiciones
</button>
<button id="live-tab" class="tab-button px-6 py-3 font-medium text-sm md:text-base" data-tab="live">
<i class="fas fa-broadcast-tower mr-2"></i>En Vivo
</button>
</div>
<!-- Teams Section -->
<section id="teams" class="tab-content active fade-in">
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
<h2 class="text-2xl font-semibold text-gray-800 mb-4">
<i class="fas fa-plus-circle text-blue-500 mr-2"></i>
Registrar Nuevo Equipo
</h2>
<form id="team-form" class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label for="team-name" class="block text-sm font-medium text-gray-700 mb-1">Nombre del Equipo</label>
<input type="text" id="team-name" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="team-coach" class="block text-sm font-medium text-gray-700 mb-1">Entrenador</label>
<input type="text" id="team-coach" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
</div>
<div class="flex items-end">
<button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-2 rounded-md transition duration-300 flex items-center">
<i class="fas fa-save mr-2"></i> Guardar
</button>
</div>
</form>
</div>
<div class="bg-white rounded-lg shadow-md p-6">
<h2 class="text-2xl font-semibold text-gray-800 mb-4">
<i class="fas fa-users text-blue-500 mr-2"></i>
Equipos Registrados
</h2>
<div id="teams-list" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
<!-- Teams will be added here dynamically -->
</div>
</div>
</section>
<!-- Matches Section -->
<section id="matches" class="tab-content hidden fade-in">
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
<h2 class="text-2xl font-semibold text-gray-800 mb-4">
<i class="fas fa-plus-circle text-blue-500 mr-2"></i>
Programar Nuevo Partido
</h2>
<form id="match-form" class="grid grid-cols-1 md:grid-cols-4 gap-4">
<div>
<label for="match-date" class="block text-sm font-medium text-gray-700 mb-1">Fecha</label>
<input type="date" id="match-date" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="match-time" class="block text-sm font-medium text-gray-700 mb-1">Hora</label>
<input type="time" id="match-time" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="home-team" class="block text-sm font-medium text-gray-700 mb-1">Equipo Local</label>
<select id="home-team" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
<option value="">Seleccionar</option>
</select>
</div>
<div>
<label for="away-team" class="block text-sm font-medium text-gray-700 mb-1">Equipo Visitante</label>
<select id="away-team" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
<option value="">Seleccionar</option>
</select>
</div>
<div class="md:col-span-4 flex justify-end">
<button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-2 rounded-md transition duration-300 flex items-center">
<i class="fas fa-calendar-plus mr-2"></i> Programar Partido
</button>
</div>
</form>
</div>
<div class="bg-white rounded-lg shadow-md p-6">
<h2 class="text-2xl font-semibold text-gray-800 mb-4">
<i class="fas fa-calendar-alt text-blue-500 mr-2"></i>
Calendario de Partidos
</h2>
<div id="matches-list" class="space-y-4">
<!-- Matches will be added here dynamically -->
</div>
</div>
</section>
<!-- Standings Section -->
<section id="standings" class="tab-content hidden fade-in">
<div class="bg-white rounded-lg shadow-md p-6">
<h2 class="text-2xl font-semibold text-gray-800 mb-4">
<i class="fas fa-table text-blue-500 mr-2"></i>
Tabla de Posiciones
</h2>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Posición</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Equipo</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">PJ</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">PG</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">PE</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">PP</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">GF</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">GC</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">DG</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Pts</th>
</tr>
</thead>
<tbody id="standings-body" class="bg-white divide-y divide-gray-200">
<!-- Standings will be added here dynamically -->
</tbody>
</table>
</div>
</div>
</section>
<!-- Live Section -->
<section id="live" class="tab-content hidden fade-in">
<div class="bg-white rounded-lg shadow-md p-6">
<h2 class="text-2xl font-semibold text-gray-800 mb-4">
<i class="fas fa-broadcast-tower text-red-500 mr-2"></i>
Partidos en Vivo
</h2>
<div id="live-matches" class="space-y-6">
<!-- Live matches will be added here dynamically -->
</div>
</div>
</section>
</div>
<!-- Team Details Modal -->
<div id="team-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md mx-4">
<div class="p-6">
<div class="flex justify-between items-center mb-4">
<h3 class="text-xl font-semibold text-gray-800" id="team-modal-title"></h3>
<button id="close-team-modal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="mb-6">
<div class="flex items-center mb-4">
<i class="fas fa-user-tie text-blue-500 mr-2"></i>
<span id="team-coach-name" class="text-gray-700"></span>
</div>
<div class="flex justify-between items-center mb-4">
<h4 class="text-lg font-medium text-gray-800">
<i class="fas fa-users text-blue-500 mr-2"></i>
Jugadores
</h4>
<button id="add-player-btn" class="text-sm bg-blue-600 hover:bg-blue-700 text-white px-3 py-1 rounded flex items-center">
<i class="fas fa-plus mr-1"></i> Agregar
</button>
</div>
<div id="players-list" class="space-y-2">
<!-- Players will be added here dynamically -->
</div>
<div id="add-player-form" class="mt-4 hidden">
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label for="player-name" class="block text-sm font-medium text-gray-700 mb-1">Nombre</label>
<input type="text" id="player-name" class="w-full px-3 py-1 border border-gray-300 rounded-md">
</div>
<div>
<label for="player-number" class="block text-sm font-medium text-gray-700 mb-1">Número</label>
<input type="number" id="player-number" min="1" max="99" class="w-full px-3 py-1 border border-gray-300 rounded-md">
</div>
</div>
<div class="flex justify-end space-x-3">
<button type="button" id="cancel-add-player" class="px-3 py-1 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-100 transition duration-300">
Cancelar
</button>
<button type="button" id="save-player" class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-1 rounded-md transition duration-300">
Guardar
</button>
</div>
</div>
</div>
<div class="flex justify-end">
<button id="close-team-modal-btn" class="bg-gray-600 hover:bg-gray-700 text-white px-4 py-2 rounded-md transition duration-300">
Cerrar
</button>
</div>
</div>
</div>
</div>
<!-- Match Details Modal -->
<div id="match-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md mx-4">
<div class="p-6">
<div class="flex justify-between items-center mb-4">
<h3 class="text-xl font-semibold text-gray-800">Actualizar Marcador</h3>
<button id="close-modal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div id="match-details" class="mb-6">
<!-- Match details will be added here -->
</div>
<form id="score-form">
<div class="grid grid-cols-2 gap-4 mb-6">
<div class="text-center">
<label class="block text-sm font-medium text-gray-700 mb-2" id="home-team-name"></label>
<input type="number" id="home-score" min="0" class="w-20 px-4 py-2 border border-gray-300 rounded-md text-center text-xl font-bold">
</div>
<div class="text-center">
<label class="block text-sm font-medium text-gray-700 mb-2" id="away-team-name"></label>
<input type="number" id="away-score" min="0" class="w-20 px-4 py-2 border border-gray-300 rounded-md text-center text-xl font-bold">
</div>
</div>
<div class="flex justify-end space-x-3">
<button type="button" id="cancel-score" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-100 transition duration-300">
Cancelar
</button>
<button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md transition duration-300">
Guardar Marcador
</button>
</div>
</form>
</div>
</div>
</div>
<script>
// Data storage
let teams = JSON.parse(localStorage.getItem('teams')) || [];
let matches = JSON.parse(localStorage.getItem('matches')) || [];
let liveMatches = JSON.parse(localStorage.getItem('liveMatches')) || [];
let currentTeamId = null;
// DOM Elements
const tabButtons = document.querySelectorAll('.tab-button');
const tabContents = document.querySelectorAll('.tab-content');
const teamForm = document.getElementById('team-form');
const teamsList = document.getElementById('teams-list');
const matchForm = document.getElementById('match-form');
const homeTeamSelect = document.getElementById('home-team');
const awayTeamSelect = document.getElementById('away-team');
const matchesList = document.getElementById('matches-list');
const standingsBody = document.getElementById('standings-body');
const liveMatchesContainer = document.getElementById('live-matches');
const matchModal = document.getElementById('match-modal');
const closeModal = document.getElementById('close-modal');
const cancelScore = document.getElementById('cancel-score');
const scoreForm = document.getElementById('score-form');
const teamModal = document.getElementById('team-modal');
const closeTeamModal = document.getElementById('close-team-modal');
const closeTeamModalBtn = document.getElementById('close-team-modal-btn');
const teamModalTitle = document.getElementById('team-modal-title');
const teamCoachName = document.getElementById('team-coach-name');
const playersList = document.getElementById('players-list');
const addPlayerBtn = document.getElementById('add-player-btn');
const addPlayerForm = document.getElementById('add-player-form');
const cancelAddPlayer = document.getElementById('cancel-add-player');
const savePlayerBtn = document.getElementById('save-player');
const playerNameInput = document.getElementById('player-name');
const playerNumberInput = document.getElementById('player-number');
let currentMatchId = null;
// Initialize the app
function init() {
renderTeams();
renderTeamSelects();
renderMatches();
renderStandings();
renderLiveMatches();
setupEventListeners();
}
// Set up event listeners
function setupEventListeners() {
// Tab navigation
tabButtons.forEach(button => {
button.addEventListener('click', () => {
const tabId = button.getAttribute('data-tab');
switchTab(tabId);
});
});
// Team form submission
teamForm.addEventListener('submit', handleTeamSubmit);
// Match form submission
matchForm.addEventListener('submit', handleMatchSubmit);
// Modal controls
closeModal.addEventListener('click', () => matchModal.classList.add('hidden'));
cancelScore.addEventListener('click', () => matchModal.classList.add('hidden'));
scoreForm.addEventListener('submit', handleScoreSubmit);
// Team modal controls
closeTeamModal.addEventListener('click', () => teamModal.classList.add('hidden'));
closeTeamModalBtn.addEventListener('click', () => teamModal.classList.add('hidden'));
// Player management
addPlayerBtn.addEventListener('click', () => {
addPlayerForm.classList.remove('hidden');
addPlayerBtn.classList.add('hidden');
});
cancelAddPlayer.addEventListener('click', () => {
addPlayerForm.classList.add('hidden');
addPlayerBtn.classList.remove('hidden');
playerNameInput.value = '';
playerNumberInput.value = '';
});
savePlayerBtn.addEventListener('click', addPlayerToTeam);
// Close modals when clicking outside
matchModal.addEventListener('click', (e) => {
if (e.target === matchModal) {
matchModal.classList.add('hidden');
}
});
teamModal.addEventListener('click', (e) => {
if (e.target === teamModal) {
teamModal.classList.add('hidden');
}
});
}
// Switch between tabs
function switchTab(tabId) {
tabButtons.forEach(button => {
button.classList.remove('active');
if (button.getAttribute('data-tab') === tabId) {
button.classList.add('active');
}
});
tabContents.forEach(content => {
content.classList.add('hidden');
content.classList.remove('active');
if (content.id === tabId) {
content.classList.remove('hidden');
content.classList.add('active');
}
});
}
// Handle team form submission
function handleTeamSubmit(e) {
e.preventDefault();
const teamName = document.getElementById('team-name').value;
const teamCoach = document.getElementById('team-coach').value;
const newTeam = {
id: Date.now().toString(),
name: teamName,
coach: teamCoach || 'Sin entrenador',
players: [],
matchesPlayed: 0,
wins: 0,
draws: 0,
losses: 0,
goalsFor: 0,
goalsAgainst: 0,
points: 0
};
teams.push(newTeam);
saveTeams();
renderTeams();
renderTeamSelects();
teamForm.reset();
}
// Handle match form submission
function handleMatchSubmit(e) {
e.preventDefault();
const date = document.getElementById('match-date').value;
const time = document.getElementById('match-time').value;
const homeTeamId = document.getElementById('home-team').value;
const awayTeamId = document.getElementById('away-team').value;
if (homeTeamId === awayTeamId) {
alert('Un equipo no puede jugar contra sí mismo');
return;
}
const homeTeam = teams.find(team => team.id === homeTeamId);
const awayTeam = teams.find(team => team.id === awayTeamId);
const newMatch = {
id: Date.now().toString(),
date: date,
time: time,
homeTeam: {
id: homeTeamId,
name: homeTeam.name,
score: null
},
awayTeam: {
id: awayTeamId,
name: awayTeam.name,
score: null
},
status: 'scheduled', // scheduled, in_progress, completed
isLive: false
};
matches.push(newMatch);
saveMatches();
renderMatches();
renderTeamSelects();
matchForm.reset();
switchTab('matches');
}
// Handle score form submission
function handleScoreSubmit(e) {
e.preventDefault();
const homeScore = parseInt(document.getElementById('home-score').value);
const awayScore = parseInt(document.getElementById('away-score').value);
const matchIndex = matches.findIndex(match => match.id === currentMatchId);
if (matchIndex !== -1) {
matches[matchIndex].homeTeam.score = homeScore;
matches[matchIndex].awayTeam.score = awayScore;
matches[matchIndex].status = 'completed';
// Remove from live matches if it was live
const liveIndex = liveMatches.findIndex(match => match.id === currentMatchId);
if (liveIndex !== -1) {
liveMatches.splice(liveIndex, 1);
saveLiveMatches();
}
// Update team statistics
updateTeamStats(
matches[matchIndex].homeTeam.id,
matches[matchIndex].awayTeam.id,
homeScore,
awayScore
);
saveMatches();
renderMatches();
renderStandings();
renderLiveMatches();
matchModal.classList.add('hidden');
}
}
// Add player to team
function addPlayerToTeam() {
const playerName = playerNameInput.value.trim();
const playerNumber = parseInt(playerNumberInput.value);
if (!playerName || isNaN(playerNumber) || playerNumber < 1 || playerNumber > 99) {
alert('Por favor ingresa un nombre válido y un número entre 1 y 99');
return;
}
const teamIndex = teams.findIndex(team => team.id === currentTeamId);
if (teamIndex !== -1) {
if (!teams[teamIndex].players) {
teams[teamIndex].players = [];
}
// Check if number is already taken
const numberTaken = teams[teamIndex].players.some(p => p.number === playerNumber);
if (numberTaken) {
alert('Este número ya está asignado a otro jugador');
return;
}
teams[teamIndex].players.push({
name: playerName,
number: playerNumber
});
saveTeams();
renderTeamPlayers(currentTeamId);
// Reset form
playerNameInput.value = '';
playerNumberInput.value = '';
addPlayerForm.classList.add('hidden');
addPlayerBtn.classList.remove('hidden');
}
}
// Open team modal to view and manage players
function openTeamModal(teamId) {
const team = teams.find(team => team.id === teamId);
if (team) {
currentTeamId = teamId;
teamModalTitle.textContent = team.name;
teamCoachName.textContent = team.coach || 'Sin entrenador';
renderTeamPlayers(teamId);
teamModal.classList.remove('hidden');
}
}
// Render players for a team
function renderTeamPlayers(teamId) {
const team = teams.find(team => team.id === teamId);
playersList.innerHTML = '';
if (!team.players || team.players.length === 0) {
playersList.innerHTML = `
<div class="text-center py-4 text-gray-500">
No hay jugadores registrados
</div>
`;
return;
}
// Sort players by number
const sortedPlayers = [...team.players].sort((a, b) => a.number - b.number);
sortedPlayers.forEach((player, index) => {
const playerItem = document.createElement('div');
playerItem.className = 'flex items-center justify-between py-2 border-b border-gray-100';
playerItem.innerHTML = `
<div class="flex items-center">
<div class="player-number">${player.number}</div>
<span class="text-gray-800">${player.name}</span>
</div>
<button onclick="removePlayer('${teamId}', ${index})" class="text-red-500 hover:text-red-700">
<i class="fas fa-trash-alt"></i>
</button>
`;
playersList.appendChild(playerItem);
});
}
// Remove player from team
function removePlayer(teamId, playerIndex) {
const teamIndex = teams.findIndex(team => team.id === teamId);
if (teamIndex !== -1 && teams[teamIndex].players && teams[teamIndex].players[playerIndex]) {
if (confirm(`¿Estás seguro de eliminar a ${teams[teamIndex].players[playerIndex].name}?`)) {
teams[teamIndex].players.splice(playerIndex, 1);
saveTeams();
renderTeamPlayers(teamId);
}
}
}
// Update team statistics based on match results
function updateTeamStats(homeTeamId, awayTeamId, homeScore, awayScore) {
const homeTeamIndex = teams.findIndex(team => team.id === homeTeamId);
const awayTeamIndex = teams.findIndex(team => team.id === awayTeamId);
if (homeTeamIndex !== -1 && awayTeamIndex !== -1) {
// Update matches played
teams[homeTeamIndex].matchesPlayed += 1;
teams[awayTeamIndex].matchesPlayed += 1;
// Update goals
teams[homeTeamIndex].goalsFor += homeScore;
teams[homeTeamIndex].goalsAgainst += awayScore;
teams[awayTeamIndex].goalsFor += awayScore;
teams[awayTeamIndex].goalsAgainst += homeScore;
// Update results and points
if (homeScore > awayScore) {
teams[homeTeamIndex].wins += 1;
teams[homeTeamIndex].points += 3;
teams[awayTeamIndex].losses += 1;
} else if (homeScore < awayScore) {
teams[awayTeamIndex].wins += 1;
teams[awayTeamIndex].points += 3;
teams[homeTeamIndex].losses += 1;
} else {
teams[homeTeamIndex].draws += 1;
teams[awayTeamIndex].draws += 1;
teams[homeTeamIndex].points += 1;
teams[awayTeamIndex].points += 1;
}
saveTeams();
}
}
// Start a live match
function startLiveMatch(matchId) {
const matchIndex = matches.findIndex(match => match.id === matchId);
if (matchIndex !== -1) {
matches[matchIndex].status = 'in_progress';
matches[matchIndex].isLive = true;
// Add to live matches if not already there
if (!liveMatches.some(match => match.id === matchId) {
liveMatches.push({...matches[matchIndex]});
saveLiveMatches();
}
saveMatches();
renderMatches();
renderLiveMatches();
switchTab('live');
}
}
// Open match modal to update score
function openMatchModal(matchId) {
const match = matches.find(match => match.id === matchId);
if (match) {
currentMatchId = matchId;
const matchDetails = document.getElementById('match-details');
matchDetails.innerHTML = `
<div class="text-center mb-4">
<p class="text-gray-600">${formatDate(match.date)} - ${match.time}</p>
</div>
<div class="flex justify-between items-center mb-2">
<div class="text-right w-2/5">
<h4 class="text-lg font-semibold">${match.homeTeam.name}</h4>
</div>
<div class="text-center w-1/5 text-xl font-bold">VS</div>
<div class="text-left w-2/5">
<h4 class="text-lg font-semibold">${match.awayTeam.name}</h4>
</div>
</div>
`;
document.getElementById('home-team-name').textContent = match.homeTeam.name;
document.getElementById('away-team-name').textContent = match.awayTeam.name;
document.getElementById('home-score').value = match.homeTeam.score || '0';
document.getElementById('away-score').value = match.awayTeam.score || '0';
matchModal.classList.remove('hidden');
}
}
// Render teams list
function renderTeams() {
teamsList.innerHTML = '';
if (teams.length === 0) {
teamsList.innerHTML = `
<div class="col-span-full text-center py-8">
<i class="fas fa-exclamation-circle text-gray-400 text-4xl mb-3"></i>
<p class="text-gray-500">No hay equipos registrados</p>
</div>
`;
return;
}
teams.forEach(team => {
const teamCard = document.createElement('div');
teamCard.className = 'bg-white border border-gray-200 rounded-lg p-4 shadow-sm hover:shadow-md transition duration-300';
teamCard.innerHTML = `
<div class="flex items-center mb-3 cursor-pointer" onclick="openTeamModal('${team.id}')">
<div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center mr-3">
<i class="fas fa-shield-alt text-blue-500"></i>
</div>
<div>
<h3 class="font-semibold text-lg">${team.name}</h3>
<p class="text-sm text-gray-500">${team.coach}</p>
</div>
</div>
<div class="grid grid-cols-2 gap-2 text-sm">
<div class="bg-gray-50 p-2 rounded">
<span class="block text-xs text-gray-500">Partidos</span>
<span class="font-medium">${team.matchesPlayed}</span>
</div>
<div class="bg-gray-50 p-2 rounded">
<span class="block text-xs text-gray-500">Puntos</span>
<span class="font-medium">${team.points}</span>
</div>
</div>
<div class="mt-3 flex justify-between items-center">
<span class="text-xs text-gray-500">
<i class="fas fa-user-friends mr-1"></i>
${team.players ? team.players.length : 0} jugadores
</span>
<button onclick="openTeamModal('${team.id}')" class="text-xs text-blue-600 hover:text-blue-800">
<i class="fas fa-edit mr-1"></i> Gestionar
</button>
</div>
`;
teamsList.appendChild(teamCard);
});
}
// Render team selects for match form
function renderTeamSelects() {
homeTeamSelect.innerHTML = '<option value="">Seleccionar</option>';
awayTeamSelect.innerHTML = '<option value="">Seleccionar</option>';
teams.forEach(team => {
const option1 = document.createElement('option');
option1.value = team.id;
option1.textContent = team.name;
homeTeamSelect.appendChild(option1);
const option2 = document.createElement('option');
option2.value = team.id;
option2.textContent = team.name;
awayTeamSelect.appendChild(option2);
});
}
// Render matches list
function renderMatches() {
matchesList.innerHTML = '';
if (matches.length === 0) {
matchesList.innerHTML = `
<div class="text-center py-8">
<i class="fas fa-calendar-times text-gray-400 text-4xl mb-3"></i>
<p class="text-gray-500">No hay partidos programados</p>
</div>
`;
return;
}
// Sort matches by date and time
const sortedMatches = [...matches].sort((a, b) => {
const dateA = new Date(`${a.date}T${a.time}`);
const dateB = new Date(`${b.date}T${b.time}`);
return dateA - dateB;
});
sortedMatches.forEach(match => {
const matchCard = document.createElement('div');
matchCard.className = 'bg-white border border-gray-200 rounded-lg p-4 shadow-sm hover:shadow-md transition duration-300';
let statusBadge = '';
let actionButton = '';
if (match.status === 'scheduled') {
statusBadge = '<span class="bg-yellow-100 text-yellow-800 text-xs px-2 py-1 rounded">Programado</span>';
actionButton = `
<button onclick="startLiveMatch('${match.id}')" class="text-blue-600 hover:text-blue-800 text-sm font-medium flex items-center">
<i class="fas fa-play-circle mr-1"></i> Iniciar
</button>
`;
} else if (match.status === 'in_progress') {
statusBadge = '<span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded flex items-center"><span class="w-2 h-2 bg-green-500 rounded-full mr-1 animate-pulse"></span> En Vivo</span>';
actionButton = `
<button onclick="openMatchModal('${match.id}')" class="text-green-600 hover:text-green-800 text-sm font-medium flex items-center">
<i class="fas fa-edit mr-1"></i> Actualizar
</button>
`;
} else if (match.status === 'completed') {
statusBadge = '<span class="bg-gray-100 text-gray-800 text-xs px-2 py-1 rounded">Finalizado</span>';
actionButton = `
<button onclick="openMatchModal('${match.id}')" class="text-gray-600 hover:text-gray-800 text-sm font-medium flex items-center">
<i class="fas fa-eye mr-1"></i> Ver
</button>
`;
}
matchCard.innerHTML = `
<div class="flex justify-between items-start mb-2">
<div>
<p class="text-sm text-gray-500">${formatDate(match.date)} - ${match.time}</p>
</div>
<div>
${statusBadge}
</div>
</div>
<div class="flex justify-between items-center mb-4">
<div class="text-right w-2/5">
<h4 class="text-lg font-semibold">${match.homeTeam.name}</h4>
</div>
<div class="text-center w-1/5">
${match.status === 'completed' ? `
<div class="text-2xl font-bold">${match.homeTeam.score} - ${match.awayTeam.score}</div>
` : `
<div class="text-xl font-bold text-gray-400">VS</div>
`}
</div>
<div class="text-left w-2/5">
<h4 class="text-lg font-semibold">${match.awayTeam.name}</h4>
</div>
</div>
<div class="flex justify-end">
${actionButton}
</div>
`;
matchesList.appendChild(matchCard);
});
}
// Render standings table
function renderStandings() {
standingsBody.innerHTML = '';
if (teams.length === 0) {
standingsBody.innerHTML = `
<tr>
<td colspan="10" class="px-6 py-4 text-center text-gray-500">
No hay equipos registrados
</td>
</tr>
`;
return;
}
// Sort teams by points, goal difference, and goals for
const sortedTeams = [...teams].sort((a, b) => {
if (b.points !== a.points) return b.points - a.points;
const diffA = a.goalsFor - a.goalsAgainst;
const diffB = b.goalsFor - b.goalsAgainst;
if (diffB !== diffA) return diffB - diffA;
return b.goalsFor - a.goalsFor;
});
sortedTeams.forEach((team, index) => {
const row = document.createElement('tr');
row.className = index % 2 === 0 ? 'bg-gray-50' : 'bg-white';
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${index + 1}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
<div class="flex items-center">
<div class="w-6 h-6 rounded-full bg-blue-100 flex items-center justify-center mr-2">
<i class="fas fa-shield-alt text-blue-500 text-xs"></i>
</div>
${team.name}
</div>
</td>
<td class="px-6 py-
</html> |