import { Navigate, Outlet, useLocation } from 'react-router-dom'
import { useIsAuthenticated } from '@features/auth'
import { ROUTES } from '@shared/config/routes'

export function ProtectedRoute() {
  const { isAuthenticated, isLoading } = useIsAuthenticated()
  const location = useLocation()

  if (isLoading) return null
  if (!isAuthenticated) return <Navigate to={ROUTES.LOGIN} state={{ from: location }} replace />
  return <Outlet />
}
