/* Application principale - Routeur SPA et logique globale */ let config = {}; let modeActuel = 'simple'; let photosSession = []; // Photos de la session en cours let photoFinale = null; // Photo finale (avec effets) let ecranActuel = 'accueil'; // --- Initialisation --- async function init() { config = await apiGet('/api/config'); appliquerConfig(); setupEcranAccueil(); setupModes(); setupOnglets(); chargerBoothInfo(); verifierPhotostationDisponible(); } function appliquerConfig() { const event = config.evenement || {}; const fonc = config.fonctionnalites || {}; // Theme const theme = event.theme || 'base'; document.documentElement.setAttribute('data-theme', theme); // Couleurs (seulement si theme base, sinon le theme CSS gere) if (theme === 'base') { document.documentElement.style.setProperty('--primaire', event.couleur_primaire || '#e91e63'); document.documentElement.style.setProperty('--secondaire', event.couleur_secondaire || '#ffffff'); } // Logo selon le theme const logo = document.getElementById('accueil-logo'); if (logo) { const logos = { sikapics: '/assets/logos/sikapics.png' }; if (logos[theme]) { logo.src = logos[theme]; logo.classList.remove('cache'); } else { logo.classList.add('cache'); } } // Nom evenement const h1 = document.getElementById('nom-evenement'); if (h1) h1.textContent = event.nom || 'Photobooth'; // Visibilite des modes toggleVisible('btn-multi', fonc.multi_shot); toggleVisible('btn-imprimer', fonc.impression); toggleVisible('btn-email', fonc.email); const boothActif = config.booth?.actif; toggleVisible('btn-qr', fonc.qr_code || boothActif); // Media d'accueil (video/gif en boucle) appliquerMediaAccueil(event.media_accueil); } function appliquerMediaAccueil(media) { const video = document.getElementById('accueil-video'); const gif = document.getElementById('accueil-gif'); const animDefaut = document.getElementById('accueil-animation-defaut'); // Reset video.classList.add('cache'); gif.classList.add('cache'); video.pause(); video.src = ''; gif.src = ''; if (!media) { // Pas de media, afficher l'animation par defaut animDefaut.classList.remove('cache'); return; } animDefaut.classList.add('cache'); const ext = media.split('.').pop().toLowerCase(); if (ext === 'gif') { gif.src = `/assets/animations/${media}`; gif.classList.remove('cache'); } else { video.src = `/assets/animations/${media}`; video.classList.remove('cache'); video.play().catch(() => {}); } } // --- Navigation --- function allerA(ecran) { const tous = document.querySelectorAll('.ecran'); tous.forEach(e => e.classList.remove('actif')); const cible = document.getElementById('ecran-' + ecran); if (cible) { cible.classList.add('actif'); ecranActuel = ecran; } // Actions au changement d'ecran if (ecran === 'accueil') { photosSession = []; photoFinale = null; arreterPreview(); majCompteurAccueil(); } else if (ecran === 'capture') { lancerCapture(); } else if (ecran === 'galerie') { chargerGalerie(); } else if (ecran === 'admin') { chargerAdmin(); } } function recommencer() { photosSession = []; photoFinale = null; allerA('mode'); } // --- Ecran accueil --- function setupEcranAccueil() { const accueil = document.getElementById('ecran-accueil'); // Toucher pour commencer (ignorer le bouton admin et le popup) accueil.addEventListener('click', (e) => { if (e.target.closest('.btn-admin')) return; allerA('mode'); }); } // --- Admin : icone + mot de passe --- const MDP_ADMIN = '1234'; const PIN_PHOTOSTATION = '1234'; let _pinPhotostationSaisi = ''; function ouvrirAdmin() { const popup = document.getElementById('popup-mdp'); const input = document.getElementById('input-mdp-admin'); popup.classList.remove('cache'); input.value = ''; document.getElementById('mdp-erreur').classList.add('cache'); } function fermerPopupMdp() { document.getElementById('popup-mdp').classList.add('cache'); document.getElementById('input-mdp-admin').value = ''; } function paveTouche(chiffre) { const input = document.getElementById('input-mdp-admin'); input.value += chiffre; } function paveEffacer() { const input = document.getElementById('input-mdp-admin'); input.value = input.value.slice(0, -1); } // --- Photostation --- async function verifierPhotostationDisponible() { const data = await apiGet('/api/photostation/disponible').catch(() => null); if (data?.disponible) { document.getElementById('btn-photostation').classList.remove('cache'); } } function ouvrirPhotostation() { _pinPhotostationSaisi = ''; _majAffichagePin(); document.getElementById('pin-photostation-erreur').classList.add('cache'); document.getElementById('popup-pin-photostation').classList.remove('cache'); } function fermerPopupPhotostation() { document.getElementById('popup-pin-photostation').classList.add('cache'); _pinPhotostationSaisi = ''; } function pinPhotostationTouche(c) { if (_pinPhotostationSaisi.length >= 4) return; _pinPhotostationSaisi += c; _majAffichagePin(); if (_pinPhotostationSaisi.length === 4) { setTimeout(_validerPinPhotostation, 150); } } function pinPhotostationEffacer() { _pinPhotostationSaisi = _pinPhotostationSaisi.slice(0, -1); _majAffichagePin(); } function _majAffichagePin() { const n = _pinPhotostationSaisi.length; const el = document.getElementById('pin-photostation-affichage'); el.textContent = '●'.repeat(n) + '○'.repeat(4 - n); } async function _validerPinPhotostation() { if (_pinPhotostationSaisi !== PIN_PHOTOSTATION) { document.getElementById('pin-photostation-erreur').classList.remove('cache'); _pinPhotostationSaisi = ''; _majAffichagePin(); return; } fermerPopupPhotostation(); afficherStatut('Lancement de la station d\'impression...', 'succes'); await apiPost('/api/photostation/lancer', {}); } function validerMdpAdmin() { const input = document.getElementById('input-mdp-admin'); if (input.value === MDP_ADMIN) { fermerPopupMdp(); allerA('admin-choix'); } else { document.getElementById('mdp-erreur').classList.remove('cache'); input.value = ''; } } function ouvrirWizard() { allerA('wizard'); wizardInit(); } // Valider avec Entree document.addEventListener('keydown', (e) => { if (e.key === 'Enter' && !document.getElementById('popup-mdp').classList.contains('cache')) { validerMdpAdmin(); } }); // --- Modes --- let cadreChoisi = null; // cadre sélectionné par l'utilisateur avant capture function setupModes() { document.querySelectorAll('#ecran-mode .btn-mode').forEach(btn => { btn.addEventListener('click', async () => { modeActuel = btn.dataset.mode; cadreChoisi = null; const hasCadres = await chargerCadresChoix(); allerA(hasCadres ? 'cadre-choix' : 'capture'); }); }); } async function chargerCadresChoix() { const cfg = await apiGet('/api/config'); const fmt = (cfg.impression?.format || '15x20').replace('-2up', ''); const data = await apiGet(`/api/cadres-impression/${fmt}`).catch(() => null); if (!data || data.disponibles.length === 0) return false; const grille = document.getElementById('grille-cadres-choix'); // Conserver "Sans cadre" en premier, supprimer les anciens cadres const aucun = grille.querySelector('.cadre-choix-aucun'); grille.innerHTML = ''; if (aucun) grille.appendChild(aucun); for (const nom of data.disponibles) { const div = document.createElement('div'); div.className = 'cadre-choix-item'; div.innerHTML = `