import { redirect } from "next/navigation";

import { LoginForm1 } from "./components/login-form-1";
import { getCurrentUser } from "@/lib/appwrite/server";

export default async function Page({
  searchParams,
}: {
  searchParams: Promise<{ invite?: string; reset?: string }>;
}) {
  const { invite, reset } = await searchParams;
  const user = await getCurrentUser();
  if (user) redirect(invite ? `/d/${invite}` : "/dashboard");

  return (
    <div className="bg-muted flex min-h-svh flex-col items-center justify-center p-6 md:p-10">
      <div className="w-full max-w-sm md:max-w-4xl">
        {reset === "success" && (
          <p className="mb-4 rounded-lg bg-green-50 px-4 py-3 text-center text-sm text-green-700">
            Şifreniz güncellendi. Giriş yapabilirsiniz.
          </p>
        )}
        <LoginForm1 inviteCode={invite} />
      </div>
    </div>
  );
}
