const SUPABASE_URL = 'https://ewmzmudqoqyqtzzijikv.supabase.co'; const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImV3bXptdWRxb3F5cXR6emlqaWt2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjYwNTYyMTYsImV4cCI6MjA4MTYzMjIxNn0.0839Hk2mbIBPhdb_YZb3UAWFa2i4vq7DjB-gMkPMbiE'; // CDN'den gelen window.supabase objesini client ile değiştir // Böylece const supabase çakışması olmaz, tüm dosyalardaki supabase.from(...) çalışır window.supabase = window.supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY); let currentUser = null; let currentProfile = null; let currentVenue = null; async function initAuth() { const { data: { session } } = await window.supabase.auth.getSession(); if (!session) { window.location.href = 'index.html'; return null; } currentUser = session.user; const { data: profile } = await window.supabase .from('profiles') .select('*') .eq('id', currentUser.id) .single(); if (!profile || profile.role !== 'business' || !profile.venue_id) { await window.supabase.auth.signOut(); window.location.href = 'index.html'; return null; } currentProfile = profile; // Venue'yu ayrı çek (RLS join sorununu bypass eder) const { data: venue } = await window.supabase .from('venues') .select('*') .eq('id', profile.venue_id) .single(); currentVenue = venue || { id: profile.venue_id, name: 'Mekanım', category: '', crowd_level: 'moderate' }; const vnEl = document.getElementById('venueName'); const vcEl = document.getElementById('venueCategory'); const uiEl = document.getElementById('userInitial'); if (vnEl) vnEl.textContent = currentVenue.name; if (vcEl) vcEl.textContent = currentVenue.category || ''; if (uiEl) uiEl.textContent = currentVenue.name?.charAt(0)?.toUpperCase() || 'M'; const currentPage = window.location.pathname.split('/').pop(); document.querySelectorAll('.nav-link').forEach(link => { if (link.getAttribute('href') === currentPage) link.classList.add('active'); }); return { user: currentUser, profile: currentProfile, venue: currentVenue }; } async function signOut() { await window.supabase.auth.signOut(); window.location.href = 'index.html'; } function formatDate(d) { if (!d) return '-'; return new Date(d).toLocaleDateString('tr-TR', { day: '2-digit', month: 'short', year: 'numeric' }); } function formatDateTime(d) { if (!d) return '-'; return new Date(d).toLocaleString('tr-TR', { day: '2-digit', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' }); } function showToast(message, type = 'success') { const t = document.createElement('div'); t.className = `toast toast-${type}`; t.innerHTML = `${type === 'success' ? '✓' : type === 'error' ? '✕' : 'ℹ'}${message}`; document.body.appendChild(t); setTimeout(() => t.classList.add('show'), 10); setTimeout(() => { t.classList.remove('show'); setTimeout(() => t.remove(), 300); }, 3000); } function confirmDialog(message) { return new Promise(resolve => { const modal = document.createElement('div'); modal.className = 'confirm-overlay'; modal.innerHTML = `
⚠️

${message}

`; document.body.appendChild(modal); setTimeout(() => modal.classList.add('show'), 10); modal.querySelector('.btn-cancel').onclick = () => { modal.remove(); resolve(false); }; modal.querySelector('.btn-confirm').onclick = () => { modal.remove(); resolve(true); }; }); }