import { redirect } from "next/navigation";
import AdminShell from "@/components/admin/AdminShell";
import SmtpSettingsForm from "@/components/admin/SmtpSettingsForm";
import { requireAdminSession } from "@/lib/admin/auth";
import { getSmtpSettings, isSmtpConfigured, toPublicSmtpSettings } from "@/lib/mail/config";

export default async function AdminSmtpPage() {
  if (!await requireAdminSession()) redirect("/admin/login");
  const settings = await getSmtpSettings();

  return (
    <AdminShell>
      <div className="admin-page-head">
        <p className="eyebrow">E-Mail</p>
        <h1>SMTP Einstellungen</h1>
      </div>
      <SmtpSettingsForm initialSettings={toPublicSmtpSettings(settings)} configured={isSmtpConfigured(settings)} />
    </AdminShell>
  );
}
