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

export default function ProtectedRoute({ children }) {
  const { user, loading } = useAuth();
  if (loading) {
    return (
      <div className="flex min-h-screen items-center justify-center bg-gradient-to-br from-brand-950 to-brand-800">
        <div className="h-12 w-12 animate-spin rounded-full border-4 border-white/20 border-t-accent-400" />
      </div>
    );
  }
  if (!user) return <Navigate to="/login" replace />;
  return children;
}
