import { useQuery } from '@tanstack/react-query';
import { supabase } from '@/integrations/supabase/client';

/**
 * Hook to fetch public Novu settings accessible to all authenticated users
 */
export function usePublicNovuSettings() {
  const { data: settings, isLoading, error } = useQuery({
    queryKey: ['public-novu-settings'],
    queryFn: async () => {
      const { data, error } = await supabase
        .from('admin_settings')
        .select('setting_key, setting_value')
        .eq('setting_key', 'novu.application_identifier')
        .maybeSingle();
      
      if (error) throw error;
      return data;
    },
  });

  const applicationIdentifier = settings?.setting_value as string || '';

  return {
    applicationIdentifier,
    isLoading,
    error,
    isEnabled: !!applicationIdentifier,
  };
}
