// Config const BOOKING_EMAIL = 'book@sabaidi.example'; // change to your inbox const WEBHOOK_URL = null; // set to an https endpoint to receive JSON payloads (optional) const THEME_KEY = 'sabaidi_theme'; const WHATSAPP_PHONE = '18090000000'; // commander function q(sel,root=document){return root.querySelector(sel)} function qa(sel,root=document){return Array.from(root.querySelectorAll(sel))} // Theme function setTheme(theme){ const root = document.documentElement; const isLight = theme === 'light'; root.classList.toggle('theme-light', isLight); localStorage.setItem(THEME_KEY, theme); const btn = document.getElementById('themeToggle'); if(btn) btn.textContent = isLight ? '🌞' : '🌙'; } function getTheme(){ return localStorage.getItem(THEME_KEY) || (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'); } // Carousel (supports multiple instances) } // Reservation form: send via mailto + optional webhook async function submitReservation(form, ok, err){ const lang = getLanguage(); const t = window.SABAIDI_I18N[lang]; const data = { name: form.name.value.trim(), phone: form.phone.value.trim(), email: form.email.value.trim(), people: form.people.value, date: form.date.value, time: form.time.value, notes: form.notes.value.trim() }; if(!data.name || !data.phone || !data.people || !data.date || !data.time){ err.style.display='block'; return; } // mailto const subject = encodeURIComponent(t.reserve_email_subject + ' • ' + data.date + ' ' + data.time + ' • ' + data.people + 'p'); const body = encodeURIComponent( `Nom: ${data.name}\nTéléphone: ${data.phone}\nEmail: ${data.email}\nCouverts: ${data.people}\nDate: ${data.date}\nHeure: ${data.time}\nNotes: ${data.notes}` ); const mailtoUrl = `mailto:${BOOKING_EMAIL}?subject=${subject}&body=${body}`; window.open(mailtoUrl, '_blank'); // optional webhook if(WEBHOOK_URL){ try{ await fetch(WEBHOOK_URL, {method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({type:'reservation', lang, ...data})}); }catch(e){ /* ignore network errors for static site */ } } ok.style.display='block'; form.reset(); } // Init reservation form function initReserveForm(){ const form = q('#reserveForm'); if(!form) return; const ok = q('#reserveOk'), err = q('#reserveErr'); form.addEventListener('submit', (e)=>{ e.preventDefault(); err.style.display='none'; ok.style.display='none'; submitReservation(form, ok, err); }); } // WhatsApp prefill (Commander) function initWhatsApp(){ const form = q('#orderForm'); if(!form) return; const btn = q('#waBtn'); const lang = getLanguage(); const t = window.SABAIDI_I18N[lang]; btn.addEventListener('click', ()=>{ const name = form.name.value.trim() || '—'; const time = form.time.value.trim() || '—'; const order = form.order.value.trim() || '—'; let msg = t.wa_template_order.replace('{order}', order).replace('{time}', time).replace('{name}', name); const url = 'https://wa.me/' + WHATSAPP_PHONE + '?text=' + encodeURIComponent(msg); window.open(url, '_blank'); }); } document.addEventListener('DOMContentLoaded', function(){ setTheme(getTheme()); startHeroCarousels(); initReserveForm(); initWhatsApp(); }); function startHeroCarousels(){ document.querySelectorAll('.hero-carousel').forEach((wrap)=>{ const slides = Array.from(wrap.querySelectorAll('img')); if(!slides.length) return; let i = 0; const show = (idx)=> slides.forEach((img, k)=> img.classList.toggle('active', k === idx)); function fit(){ const img = slides[i]; let ratio = (img.naturalWidth && img.naturalHeight) ? img.naturalHeight / img.naturalWidth : (9/16); const h = Math.max(260, Math.min(640, Math.round(wrap.clientWidth * ratio))); wrap.style.height = h + 'px'; } slides.forEach(img => img.addEventListener('load', fit, {once:false})); show(0); setTimeout(fit, 50); window.addEventListener('resize', fit); setInterval(()=>{ i = (i+1) % slides.length; show(i); fit(); }, 3000); }); }