import { useEffect, useState } from 'react';
import { checkAccess } from '@/lib/auth-guard';

export function useAuthGuard() {
  const [status, setStatus] = useState('loading'); // loading | allowed | unauthenticated | denied
  const [user, setUser] = useState(null);

  useEffect(() => {
    checkAccess().then(result => {
      if (result.allowed) {
        setUser(result.user);
        setStatus('allowed');
      } else {
        setStatus(result.reason);
      }
    });
  }, []);

  return { status, user };
}