// supabase-client.jsx — single Supabase client shared by all saraslot frontend files.
// Loaded after the supabase UMD bundle and before auth.jsx/data.jsx/pages.jsx.

const SUPABASE_URL = "https://qewkjhgwuaqxxqaophxi.supabase.co";
const SUPABASE_KEY = "sb_publishable_ZHvHoPgmfxf9BQ06F5GEjA_VQJ8pc4N";

// supabase UMD exposes `window.supabase` with createClient on it.
window.sb = window.supabase.createClient(SUPABASE_URL, SUPABASE_KEY, {
  auth: {
    persistSession: true,
    autoRefreshToken: true,
    detectSessionInUrl: false,
  },
});

// Synthesize a stable email from a phone number for Supabase Auth.
// We don't enable Supabase Phone provider (skip SMS / OTP for MVP), but UX shows
// the user a phone field. Internally we sign up/sign in with email+password using
// a deterministic email derived from the phone. The real phone is stored on
// public.profiles.phone (unique).
window.phoneToEmail = function phoneToEmail(phone) {
  const digits = String(phone || "").replace(/\D+/g, "");
  return `p${digits}@phone.saraslot.local`;
};
