import { useAuth } from '@/components/auth/AuthContext';
import { useState, useEffect } from 'react';

export function useSponsorMode(): boolean {
  const { session } = useAuth();
  const [isSponsor, setIsSponsor] = useState(false);
  
  useEffect(() => {
    if (!session) {
      setIsSponsor(false);
      return;
    }

    // Check session.role for sponsor
    const role = session.role;
    if (role === 'sponsor') {
      setIsSponsor(true);
      return;
    }

    // Fallback: check email patterns
    const email = session.email?.toLowerCase() || '';
    const displayName = session.displayName?.toLowerCase() || '';
    
    setIsSponsor(email.includes('sponsor') || displayName.includes('sponsor'));
  }, [session]);
  
  return isSponsor;
}
