let supabase = null;
function initSupabase() {
if (window.supabase && SUPABASE_URL.includes('supabase.co') && !SUPABASE_URL.includes('XXXX')) {
supabase = window.supabase.createClient(SUPABASE_URL, SUPABASE_KEY);
}
}
// ---- AUTH STATE ----
let currentUser = null; // Supabase user objesi
let currentProfile = null; // profiles tablosundaki kayıt
let selectedPlan = 'monthly';
// Demo modu: Supabase bağlı değilse localStorage ile simüle et
function isDemoMode() { return !supabase; }
function getDemoUser() {
const u = localStorage.getItem('ha_demo_user');
return u ? JSON.parse(u) : null;
}
function setDemoUser(u) {
if (u) localStorage.setItem('ha_demo_user', JSON.stringify(u));
else localStorage.removeItem('ha_demo_user');
}
function getDemoComments(articleId) {
const raw = localStorage.getItem('ha_comments_' + articleId);
return raw ? JSON.parse(raw) : [];
}
function saveDemoComment(articleId, comment) {
const list = getDemoComments(articleId);
list.unshift(comment);
localStorage.setItem('ha_comments_' + articleId, JSON.stringify(list));
}
// ---- ARTICLE ID ----
function getArticleId(art) {
// URL'den benzersiz ID üret
return btoa(art.link).replace(/[^a-z0-9]/gi,'').substring(0,32);
}
// ---- AUTH AREA RENDER ----
function renderAuthArea() {
const el = document.getElementById('comment-auth-area');
if (!el) return;
const user = isDemoMode() ? getDemoUser() : currentProfile;
if (!user) {
// Giriş / Kayıt formu
el.innerHTML = `