import { ModuleScaffold } from "@/components/admin/module-scaffold";
import { getAdminPing } from "@/api";
import { dashboardModuleMeta } from "@/modules/dashboard/meta";
import type { Metadata } from "next";

export const metadata: Metadata = {
  title: "总览",
};

export default async function AdminDashboardPage() {
  const ping = await getAdminPing();
  const apiReady = process.env.NEXT_PUBLIC_LOTTERY_API_BASE_URL?.trim() !== "";

  return (
    <ModuleScaffold
      title={dashboardModuleMeta.title}
      description={dashboardModuleMeta.description}
    >
      <div className="grid gap-4 sm:grid-cols-2">
        <div className="rounded-xl border border-black/10 bg-white p-5 shadow-sm dark:border-white/10 dark:bg-zinc-900">
          <h2 className="text-xs font-semibold uppercase tracking-wide text-zinc-500 dark:text-zinc-400">
            API 基底
          </h2>
          <p className="mt-2 text-sm text-foreground">
            {apiReady ? (
              <span className="font-medium text-emerald-600 dark:text-emerald-400">
                已配置 NEXT_PUBLIC_LOTTERY_API_BASE_URL
              </span>
            ) : (
              <span className="font-medium text-amber-600 dark:text-amber-400">
                未配置环境变量，无法在服务端探测 Laravel
              </span>
            )}
          </p>
          <p className="mt-3 text-xs leading-relaxed text-zinc-500 dark:text-zinc-400">
            与玩家端一致，指向 Laravel 根地址（会自动请求{" "}
            <code className="rounded bg-zinc-100 px-1 py-0.5 dark:bg-zinc-800">
              /api/v1/admin/ping
            </code>
            ）。
          </p>
        </div>
        <div className="rounded-xl border border-black/10 bg-white p-5 shadow-sm dark:border-white/10 dark:bg-zinc-900">
          <h2 className="text-xs font-semibold uppercase tracking-wide text-zinc-500 dark:text-zinc-400">
            Admin Ping
          </h2>
          <p className="mt-2 font-mono text-sm text-foreground">
            {!apiReady ? "—" : ping ? JSON.stringify(ping) : "请求失败或未返回信封"}
          </p>
        </div>
      </div>
    </ModuleScaffold>
  );
}
