import { Navigate, Outlet } from "react-router-dom"
import { Spinner } from "@heroui/react"
import { useAuth } from "../contexts/AuthContext"

export default function ProtectedRoute() {
  const { user, isLoading } = useAuth()

  if (isLoading) {
    return (
      <div className="flex h-screen items-center justify-center bg-white">
        <Spinner size="lg" />
      </div>
    )
  }

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

  return <Outlet />
}
