import { Navigate, useLocation } from "react-router";
import { useAuthStore } from "../../stores/authStore";

interface Props {
  children: React.ReactNode;
}

export function PrivateRoute({ children }: Props) {
  const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
  const location = useLocation();

  if (!isAuthenticated) {
    return <Navigate to="/login" state={{ from: location }} replace />;
  }

  return <>{children}</>;
}
