import { redirect } from "next/navigation";
import AdminShell from "@/components/admin/AdminShell";
import { requireAdminSession } from "@/lib/admin/auth";
import { adminConfigurationStatus, appVersion, checkStorage, dataDirectory, isDockerEnvironment, olympusStatus, smtpStatus, uploadDirectory } from "@/lib/runtime/config";

export default async function AdminSystemPage() {
  if (!await requireAdminSession()) redirect("/admin/login");
  let storage = "ok";

  try {
    await checkStorage();
  } catch {
    storage = "error";
  }

  return (
    <AdminShell>
      <div className="admin-page-head">
        <p className="eyebrow">Betrieb</p>
        <h1>System</h1>
      </div>
      <section className="admin-card">
        <h2>Runtime Informationen</h2>
        <dl className="system-list">
          <div><dt>Version</dt><dd>{appVersion}</dd></div>
          <div><dt>Node Version</dt><dd>{process.version}</dd></div>
          <div><dt>Docker Environment</dt><dd>{isDockerEnvironment() ? "ja" : "nein"}</dd></div>
          <div><dt>Storage Status</dt><dd>{storage}</dd></div>
          <div><dt>Data Directory</dt><dd>{dataDirectory}</dd></div>
          <div><dt>Upload Directory</dt><dd>{uploadDirectory}</dd></div>
          <div><dt>Admin Konfiguration</dt><dd>{adminConfigurationStatus()}</dd></div>
          <div><dt>Olympus Verbindung</dt><dd>{olympusStatus()}</dd></div>
          <div><dt>SMTP</dt><dd>{smtpStatus()}</dd></div>
        </dl>
      </section>
      <section className="admin-card">
        <h2>Betriebsregeln</h2>
        <ul className="list">
          <li>Runtime-Daten liegen unter <code>data/</code> und werden nicht versioniert.</li>
          <li>Uploads liegen unter <code>public/uploads/images/</code> und werden nicht versioniert.</li>
          <li>Olympus- und SMTP-Integration sind vorbereitet, aber nicht aktiv implementiert.</li>
        </ul>
      </section>
    </AdminShell>
  );
}
