// config.jsx — Supabase-Verbindung
//
// MUSS vor prototype.jsx + dashboard.jsx geladen werden (siehe HTML).
// Der anon-Key ist absichtlich öffentlich: Row Level Security + SECURITY DEFINER
// Funktionen sorgen dafür, dass damit nur die wedding_* RPCs aufrufbar sind.

const SUPABASE_URL      = "https://gmbfznswkjwibqywzeiw.supabase.co";
const SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImdtYmZ6bnN3a2p3aWJxeXd6ZWl3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Nzk3MzkyNzUsImV4cCI6MjA5NTMxNTI3NX0.PupwTgwAmdEpfe4i0T8FoKOj5M5w-U6capam2AZq8Zs";

// RPC-Helper: ruft eine wedding_*-Funktion in Supabase auf.
// → gibt das JSON-Resultat zurück, oder wirft bei HTTP-Fehler.
const supaRpc = async (fn, params = {}) => {
  const r = await fetch(`${SUPABASE_URL}/rest/v1/rpc/${fn}`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "apikey": SUPABASE_ANON_KEY,
      "Authorization": `Bearer ${SUPABASE_ANON_KEY}`,
    },
    body: JSON.stringify(params),
  });
  if (!r.ok) {
    const text = await r.text().catch(() => "");
    throw new Error(`RPC ${fn} failed: ${r.status} ${text}`);
  }
  return await r.json();
};

// Constants
const RSVP_DEADLINE = new Date("2026-07-15T23:59:59");
const SESSION_KEY   = "wedding-session";
