import { useContext, useDebugValue } from 'react';
import { AuthContext } from '../components/auth/AuthProvider';
import { AuthContextType } from '../types/auth.types';

export const useAuth = (): AuthContextType => {
  const context = useContext(AuthContext);
  
  if (!context) {
    throw new Error('useAuth must be used within an AuthProvider');
  }

  useDebugValue(context, (ctx) => ({
    isAuthenticated: ctx.isAuthenticated,
    user: ctx.user?.email,
  }));

  return context;
};