import { LoginForm } from "@code/auth/web";
import { useNavigate, useSearchParams } from "react-router";

import type { Route } from "./+types/page";

export const meta = (_args: Route.MetaArgs) => [
  { title: "Sign in | Zopu" },
  { content: "Sign in to Zopu", name: "description" },
];

export default function LoginRoute() {
  const navigate = useNavigate();
  const [searchParams] = useSearchParams();
  const returnTo = searchParams.get("returnTo");

  return (
    <LoginForm
      onSuccess={() =>
        navigate(returnTo?.startsWith("/") ? returnTo : "/", { replace: true })
      }
    />
  );
}
