import { createClient, SupabaseClient, Session, User } from "@supabase/supabase-js";

// Default Supabase configuration (can be overridden by environment variables)
const DEFAULT_SUPABASE_URL = "https://jalcdbwvbzvtxrwduwop.supabase.co";
const DEFAULT_SUPABASE_ANON_KEY = "sb_publishable_7aM3npUD3py5tVei-juGJw_PmdT-hl0";

// Use environment variables if set, otherwise fall back to defaults
export const SUPABASE_URL = import.meta.env.VITE_SUPABASE_URL || DEFAULT_SUPABASE_URL;
const SUPABASE_ANON_KEY = import.meta.env.VITE_SUPABASE_ANON_KEY || DEFAULT_SUPABASE_ANON_KEY;

// Create Supabase client with default or overridden configuration
export const supabase: SupabaseClient = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
  auth: {
    autoRefreshToken: true,
    persistSession: true,
    detectSessionInUrl: true,
  },
});

export function isAuthConfigured(): boolean {
  return true;
}

export type { Session, User };
