import React from 'react'; import { Navigate } from 'react-router-dom'; import { useAuth } from '@/hooks/useAuth'; import { useUserRole } from '@/hooks/useUserRole'; import { useUserProfile } from '@/hooks/useUserProfile'; interface ProtectedAdminRouteProps { children: React.ReactNode; } export const ProtectedAdminRoute: React.FC = ({ children }) => { const { user, loading: authLoading } = useAuth(); const { isAdmin, loading: roleLoading } = useUserRole(); const { profile, loading: profileLoading } = useUserProfile(); const loading = authLoading || roleLoading || profileLoading; if (loading) { return (
Carregando...
); } if (!user) { return ; } // Verificar se o usuário está ativo no sistema if (profile && profile.status !== 'active') { return (

Acesso Bloqueado

Seu usuário existe, mas encontra-se com status: {profile.status || 'pendente'}.

Por favor, contate o administrador para aprovar o seu acesso.

); } if (!isAdmin) { return ; } return <>{children}; };