import type { Metadata } from "next";
import { redirect } from "next/navigation";
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth";

export const metadata: Metadata = {
  title: "Masuk",
  description:
    "Masuk ke akun SeTrip untuk gabung open trip & aktivitas bareng dan kelola perjalananmu.",
  alternates: { canonical: "/login" },
  robots: { index: false, follow: true },
};

export default async function LoginLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  // User yang sudah login tidak boleh mengakses halaman login lagi.
  const session = await getServerSession(authOptions);
  if (session?.user) {
    redirect(session.user.isAdmin ? "/admin" : "/");
  }
  return children;
}
