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

export function AdminRoute() {
  const { ready, token, isAdmin } = useAuth();
  if (!ready) return <p className="loading">載入中…</p>;
  if (!token) return <Navigate to="/login" replace />;
  if (!isAdmin) return <Navigate to="/app" replace />;
  return <Outlet />;
}
