// This file is automatically generated. Do not edit it directly.
import { createClient } from '@supabase/supabase-js';
import type { Database } from './types';

// ---------------------------------------------------------------------------
// Tolerant initialisation
// ---------------------------------------------------------------------------
// Nadiplayer ships with a PHP/cPanel backend (not Supabase). The Supabase
// client is only retained as a legacy proxy path for users who actually
// configure VITE_SUPABASE_URL. When those env vars are absent we MUST NOT
// call createClient() with `undefined` — supabase-js v2 throws
// `supabaseUrl is required`, which crashes the whole bundle at module
// load (the import is static, pulled in by lib/proxy.ts) and leaves the
// Tizen / Web / Android WebView stuck on the splash background.
//
// The runtime guard in lib/proxyEndpoint.ts (`proxyMode() === "supabase"`)
// makes sure none of the methods on this stub are ever called unless the
// user has supplied a real *.supabase.co URL.
// ---------------------------------------------------------------------------

const RAW_URL = import.meta.env.VITE_SUPABASE_URL as string | undefined;
const RAW_KEY = import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY as string | undefined;

const PLACEHOLDER_URL = "https://placeholder.supabase.co";
const PLACEHOLDER_KEY = "placeholder-anon-key";

const SUPABASE_URL = RAW_URL && RAW_URL.trim().length > 0 ? RAW_URL : PLACEHOLDER_URL;
const SUPABASE_PUBLISHABLE_KEY =
  RAW_KEY && RAW_KEY.trim().length > 0 ? RAW_KEY : PLACEHOLDER_KEY;

// Import the supabase client like this:
// import { supabase } from "@/integrations/supabase/client";

export const supabase = createClient<Database>(SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, {
  auth: {
    storage: localStorage,
    persistSession: true,
    autoRefreshToken: true,
  }
});
