import { Navigate, Outlet } from "react-router-dom"
import { Spin } from "antd"
import { useAdminAuth } from "../contexts/AdminAuthContext"

export default function AdminProtectedRoute() {
  const { admin, isLoading } = useAdminAuth()

  if (isLoading) {
    return (
      <div style={{ minHeight: "100vh", display: "flex", alignItems: "center", justifyContent: "center", background: "#fff" }}>
        <Spin size="large" />
      </div>
    )
  }

  if (!admin) {
    return <Navigate to="/admin/login" replace />
  }

  return <Outlet />
}
