import { createClient } from '@supabase/supabase-js'
import type { Database } from './database.types'

// Use PUBLIC_ prefixed variables for client-side, fallback to server-side for SSR
const supabaseUrl = import.meta.env.PUBLIC_SUPABASE_URL || import.meta.env.SUPABASE_URL
const supabaseAnonKey = import.meta.env.PUBLIC_SUPABASE_ANON_KEY || import.meta.env.SUPABASE_ANON_KEY

if (!supabaseUrl || !supabaseAnonKey) {
  throw new Error('Missing required Supabase environment variables. Make sure SUPABASE_URL and SUPABASE_ANON_KEY are set.')
}

export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey)

