import { Navigate, Outlet, useLocation } from 'react-router-dom'
import { useAuth } from '../context/AuthContext'

export default function RequireAdmin() {
  const { isAdmin } = useAuth()
  const loc = useLocation()
  if (!isAdmin) {
    return <Navigate to="/" replace state={{ from: loc.pathname, adminDenied: true }} />
  }
  return <Outlet />
}
