import { useAuthContext } from './chunk-BRJ3QZ4E.js';
import { createClient } from '@supabase/supabase-js';
import { useMemo } from 'react';

function getSupabaseConfig() {
  const url = import.meta.env?.VITE_SUPABASE_URL;
  const anonKey = import.meta.env?.VITE_SUPABASE_ANON_KEY;
  if (!url || !anonKey) {
    throw new Error("Missing Supabase environment variables (VITE_SUPABASE_URL, VITE_SUPABASE_ANON_KEY)");
  }
  return { url, anonKey };
}
var useSupabase = () => {
  const { getAccessToken } = useAuthContext();
  const { url, anonKey } = getSupabaseConfig();
  return useMemo(
    () => createClient(url, anonKey, {
      global: {
        headers: {
          // Additional headers if needed
        }
      },
      accessToken: async () => {
        try {
          const token = await getAccessToken();
          if (!token) {
            return null;
          }
          return token;
        } catch {
          return null;
        }
      }
    }),
    [getAccessToken, url, anonKey]
  );
};

export { useSupabase };
