/**
 * earth-now.co
 * Author:  Simon-Pierre Boucher
 * Contact: contact@spboucher.ai
 * File:    apps/web/app/page.tsx
 * Purpose: Home page (server component) — fetches registry metrics + counter models and hands off to the client dashboard; friendly API-offline state
 */

import Dashboard from "@/components/Dashboard";
import { fetchMetrics, fetchModels } from "@/lib/api";

export const dynamic = "force-dynamic";

export default async function HomePage() {
  try {
    const [metrics, modelsResponse] = await Promise.all([fetchMetrics(), fetchModels()]);
    return <Dashboard metrics={metrics} initialModels={modelsResponse.models} />;
  } catch {
    // Never crash the page when apps/api is down — render a calm offline state.
    return (
      <div className="mx-auto flex max-w-2xl flex-col items-center gap-3 px-4 py-24 text-center">
        <p className="text-4xl" aria-hidden>
          🛰️
        </p>
        <h1 className="text-xl font-semibold text-ink">
          API hors ligne / API offline
        </h1>
        <p className="text-sm text-ink2">
          Les compteurs sont momentanément indisponibles — le serveur de modèles ne répond pas.
          Réessayez dans un instant.
        </p>
        <p className="text-sm text-muted">
          Counters are momentarily unavailable — the model server is not responding. Please try
          again shortly.
        </p>
      </div>
    );
  }
}
