import type { Metadata } from "next";
import AppBar from "@/components/AppBar";
import { getServerSession } from "next-auth";
import { authOptions } from "@/config/authConfig";
import { redirect } from "next/navigation";

export const metadata: Metadata = {
  title: "Dashboard",
};

export default async function DashboardLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const session = await getServerSession(authOptions);
  console.log(session);

  if (!session?.user) {
    redirect("/login");
  }

  return (
    <>
      <AppBar
        profileName={session.user.name!}
        avatarImageSrc={session.user.image || undefined}
      />
      <main>{children}</main>
    </>
  );
}
