import type { Metadata } from "next";
import { requireAuth } from "@/lib/auth/guards";
import { prisma } from "@/lib/db";
import { PageHeader } from "@/components/app/page-header";
import { SettingsClient } from "@/components/app/settings-client";

export const metadata: Metadata = { title: "Settings" };

export default async function SettingsPage() {
  const session = await requireAuth();

  const prefs = await prisma.userPreferences.findUnique({
    where: { userId: session.user.id },
  });

  return (
    <>
      <PageHeader title="Settings" description="Manage your account." />
      <SettingsClient
        name={session.user.name}
        email={session.user.email}
        preferences={{
          defaultVoiceId: prefs?.defaultVoiceId ?? null,
          defaultLanguage: prefs?.defaultLanguage ?? "en",
          emailOnEpisodeReady: prefs?.emailOnEpisodeReady ?? true,
          productEmails: prefs?.productEmails ?? true,
        }}
      />
    </>
  );
}
