import type { Metadata } from "next";
import { DownloadCard } from "@/components/DownloadCard";
import { GlassCard } from "@/components/GlassCard";
import { ProgressPill } from "@/components/ProgressPill";
import { getLatestManifest, getReleasesCatalog } from "@/lib/releases";

export const dynamic = "force-static";

export const metadata: Metadata = {
  title: "Downloads",
  description: "Download Ninja Nexus POC builds, NexusSetup.exe og Ninja Nexus Dev Pack.",
  alternates: { canonical: "https://nexus.ninjakernen.info/downloads" },
};

export default async function DownloadsPage() {
  const [catalog, latest] = await Promise.all([getReleasesCatalog(), getLatestManifest()]);

  return (
    <div className="mx-auto max-w-6xl px-4 py-12 sm:px-6">
      <div className="flex flex-wrap items-center gap-3">
        <h1 className="text-3xl font-bold text-nexus-navy">Downloads</h1>
        <ProgressPill label="POC · Safe mode only" variant="amber" />
      </div>
      <p className="mt-3 text-nexus-muted">
        Seneste builds — installer og ZIP-pakker. Build 91 er anbefalet POC-baseline.
      </p>

      <GlassCard glow className="mt-6">
        <div className="flex flex-wrap items-center gap-2">
          <h2 className="text-xl font-semibold text-nexus-navy">Ninja Nexus Dev Pack</h2>
          <ProgressPill label="Codex-ready" variant="brand" />
        </div>
        <p className="mt-3 text-sm text-nexus-muted">
          Public-safe kildekode-snapshot af hele Ninja Nexus projektet til en udviklings-laptop:
          source, docs, tests, deployment scripts og website source. Lokale caches, .git,
          node_modules, build-output og untracked filer er udeladt.
        </p>
        <div className="mt-4 flex flex-wrap gap-2 text-sm">
          <a href="/downloads/dev-pack/ninja-nexus-dev-pack.zip" className="btn-brand rounded-xl px-4 py-2">
            Download Dev Pack ZIP
          </a>
          <a
            href="/downloads/dev-pack/dev-pack.json"
            className="btn-brand-outline rounded-xl px-4 py-2"
          >
            dev-pack.json
          </a>
          <a
            href="/downloads/dev-pack/sha256.txt"
            className="rounded-xl px-4 py-2 text-nexus-muted underline-offset-2 hover:underline"
          >
            SHA256
          </a>
        </div>
      </GlassCard>

      {latest && (
        <GlassCard glow className="mt-6">
          <p className="text-sm text-nexus-muted">Seneste ifølge latest.json</p>
          <p className="mt-1 text-lg font-semibold text-nexus-navy">
            Build {latest.build} · {latest.version}
          </p>
          <div className="mt-3 flex flex-wrap gap-2 text-sm">
            <a
              href="/downloads/latest.json"
              className="rounded-lg border border-nexus-border px-3 py-1 hover:border-[#A855F7]/35"
            >
              latest.json
            </a>
            <a
              href="/downloads/releases.json"
              className="rounded-lg border border-nexus-border px-3 py-1 hover:border-[#A855F7]/35"
            >
              releases.json
            </a>
          </div>
        </GlassCard>
      )}

      <GlassCard className="mt-6">
        <h2 className="font-semibold text-nexus-navy">Sådan installerer du</h2>
        <ol className="mt-3 list-inside list-decimal space-y-2 text-sm text-nexus-muted">
          <li>Download NexusSetup.exe (build 91 anbefales)</li>
          <li>Kør som administrator</li>
          <li>Standard POC-sti: C:\NinjaNexusPOC</li>
          <li>Krav: .NET 8 Runtime + .NET Desktop Runtime</li>
          <li>Auto-update tjekker /downloads/latest.json ved shell-start</li>
        </ol>
      </GlassCard>

      <div className="mt-8 space-y-6">
        {catalog.releases.map((release) => (
          <DownloadCard key={release.build} release={release} />
        ))}
      </div>
    </div>
  );
}
