import { redirect } from "next/navigation";
import AdminShell from "@/components/admin/AdminShell";
import { requireAdminSession } from "@/lib/admin/auth";
import { getSmtpSettings } from "@/lib/admin/store";

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>
      <form className="admin-card admin-form" action="/api/admin/smtp" method="post">
        <label>SMTP Server<input name="host" defaultValue={settings.host} /></label>
        <label>Port<input name="port" defaultValue={settings.port} inputMode="numeric" /></label>
        <label>Benutzername<input name="username" defaultValue={settings.username} /></label>
        <label>Passwort<input name="password" type="password" placeholder="wird in dieser Foundation noch nicht gespeichert" disabled /></label>
        <label>Absenderadresse<input name="fromAddress" type="email" defaultValue={settings.fromAddress} /></label>
        <label>Antwortadresse<input name="replyToAddress" type="email" defaultValue={settings.replyToAddress} /></label>
        <label className="admin-checkbox"><input name="tls" type="checkbox" defaultChecked={settings.tls} /> TLS aktivieren</label>
        <button className="button" type="submit">Speichern</button>
      </form>
    </AdminShell>
  );
}
