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

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

  return (
    <AdminShell>
      <div className="admin-page-head">
        <p className="eyebrow">Konfiguration</p>
        <h1>Firmeneinstellungen</h1>
      </div>
      <form className="admin-card admin-form" action="/api/admin/settings" method="post">
        <label>Firmenname<input name="companyName" defaultValue={settings.companyName} /></label>
        <label>Telefon<input name="phone" defaultValue={settings.phone} /></label>
        <label>E-Mail<input name="email" type="email" defaultValue={settings.email} /></label>
        <label>Adresse<input name="address" defaultValue={settings.address} /></label>
        <label>Öffnungszeiten<input name="openingHours" defaultValue={settings.openingHours} /></label>
        <label>Google Maps Embed URL<input name="googleMapsEmbedUrl" defaultValue={settings.googleMapsEmbedUrl} /></label>
        <label>Social Links<textarea name="socialLinks" defaultValue={settings.socialLinks} /></label>
        <button className="button" type="submit">Speichern</button>
      </form>
    </AdminShell>
  );
}
