import { DataLoader } from './data-loader.js'; import { HallOfFameGenerator, HallOfFameQuestion } from './hall-of-fame-generator.js'; class GitHubWrappedHallOfFame { private dataLoader: DataLoader; private generator?: HallOfFameGenerator; private questions: HallOfFameQuestion[] = []; private currentIndex = 0; constructor() { this.dataLoader = new DataLoader(); } async init(): Promise { try { const data = await this.dataLoader.load(); this.generator = new HallOfFameGenerator(data); this.questions = this.generator.getQuestions(); this.showWelcome(); } catch (error) { this.showError('Erreur de chargement. Verifiez que data.json existe.'); } } private showWelcome(): void { const container = document.getElementById('app')!; const peopleCount = this.generator!.getPeopleCount(); container.innerHTML = `
← Accueil
🏆

Hall of Fame

Chaque membre a son moment de gloire!

${peopleCount}
Membres Célèbres
${this.questions.length}
Achievements

Chaque personne brille dans son domaine unique!

`; document.getElementById('startBtn')?.addEventListener('click', () => { this.showAchievement(0); }); } private showAchievement(index: number): void { if (index >= this.questions.length) { this.showFinalCelebration(); return; } this.currentIndex = index; const achievement = this.questions[index]; const container = document.getElementById('app')!; container.innerHTML = `
← Accueil
${index + 1} / ${this.questions.length}
${index > 0 ? ` ` : '
'}
${achievement.emoji}
${achievement.title}
${this.getInitials(achievement.person)}

${achievement.person}

${achievement.category}
${achievement.stat.label}
${achievement.stat.value}
🎖️
${achievement.achievement}
${achievement.funFact}
${achievement.special ? `
🌟 Spécial
${achievement.special.description}
` : ''}
`; // Trigger confetti animation this.triggerConfetti(); // Event listeners document.getElementById('nextBtn')?.addEventListener('click', () => { this.showAchievement(index + 1); }); if (index > 0) { document.getElementById('prevBtn')?.addEventListener('click', () => { this.showAchievement(index - 1); }); } // Keyboard navigation const handleKeyPress = (e: KeyboardEvent) => { if (e.key === 'ArrowRight' || e.key === 'Enter' || e.key === ' ') { e.preventDefault(); document.removeEventListener('keydown', handleKeyPress); this.showAchievement(index + 1); } else if (e.key === 'ArrowLeft' && index > 0) { e.preventDefault(); document.removeEventListener('keydown', handleKeyPress); this.showAchievement(index - 1); } }; document.addEventListener('keydown', handleKeyPress); } private showFinalCelebration(): void { const container = document.getElementById('app')!; const allPeople = [...new Set(this.questions.map(q => q.person))]; container.innerHTML = `
← Accueil
🏆

Bravo à Tous!

Chacun a brillé à sa manière

${allPeople.length}
Champions
${this.questions.length}
Achievements
${allPeople.map(person => `
${this.getInitials(person)}
${person}
`).join('')}

"Seul on va plus vite, ensemble on va plus loin"

Merci à toute l'équipe pour cette année incroyable!

🏠 Retour à l'Accueil
`; // Massive confetti! this.triggerMassiveConfetti(); document.getElementById('replayBtn')?.addEventListener('click', () => { this.showAchievement(0); }); } private getInitials(name: string): string { return name .split(' ') .map(part => part.charAt(0).toUpperCase()) .join('') .substring(0, 2); } private triggerConfetti(): void { // Create simple confetti effect const container = document.querySelector('.hall-achievement-container'); if (!container) return; for (let i = 0; i < 30; i++) { const confetti = document.createElement('div'); confetti.className = 'confetti'; confetti.style.left = Math.random() * 100 + '%'; confetti.style.animationDelay = Math.random() * 0.5 + 's'; confetti.style.backgroundColor = this.getRandomColor(); container.appendChild(confetti); setTimeout(() => confetti.remove(), 3000); } } private triggerMassiveConfetti(): void { const container = document.querySelector('.hall-finale'); if (!container) return; for (let i = 0; i < 80; i++) { const confetti = document.createElement('div'); confetti.className = 'confetti massive'; confetti.style.left = Math.random() * 100 + '%'; confetti.style.animationDelay = Math.random() * 2 + 's'; confetti.style.backgroundColor = this.getRandomColor(); container.appendChild(confetti); setTimeout(() => confetti.remove(), 5000); } } private getRandomColor(): string { const colors = ['#00ffff', '#ff006e', '#b537f2', '#fffd01', '#39ff14', '#ff6c11']; return colors[Math.floor(Math.random() * colors.length)]; } private showError(message: string): void { const container = document.getElementById('app')!; container.innerHTML = `

Erreur

${message}

Retour aux Stats
`; } } // Initialize the Hall of Fame const hallOfFame = new GitHubWrappedHallOfFame(); hallOfFame.init();