import { Navigate } from 'react-router-dom'
import { useAuth } from '@/context/AuthContext'

export function ProtectedRoute({ children, requireAdmin = false }: {
  children: React.ReactNode
  requireAdmin?: boolean
}) {
  const { user, isLoading } = useAuth()

  if (isLoading) return <div className="flex items-center justify-center h-screen">Laden...</div>
  if (!user) return <Navigate to="/login" replace />
  if (requireAdmin && user.role !== 'admin') return <div className="p-8">Zugriff verweigert</div>

  return <>{children}</>
}
