import React from 'react'
import { Navigate, Outlet, useLocation } from 'react-router-dom'
import { getAdminToken } from '../../utils/api'

export default function RequireAdmin() {
  const token = getAdminToken()
  const location = useLocation()

  if (!token) {
    return <Navigate to="/admin/login" replace state={{ from: location }} />
  }

  return <Outlet />
}
