import { AdminPermissionGate } from "@/components/admin/admin-permission-gate";
import { ModuleScaffold } from "@/components/admin/module-scaffold";
import { PRD_PLAYERS_ACCESS_ANY } from "@/lib/admin-prd";
import { buildPageMetadata } from "@/lib/page-metadata";
import { InvalidPlayerId } from "@/modules/players/invalid-player-id";
import { PlayerDetailConsole } from "@/modules/players/player-detail-console";
import type { Metadata } from "next";

export const metadata: Metadata = buildPageMetadata("players", "detailTitle");

export default async function AdminPlayerDetailPage(props: {
  params: Promise<{ playerId: string }>;
}) {
  const { playerId } = await props.params;
  const id = Number(playerId);

  return (
    <ModuleScaffold>
      <AdminPermissionGate requiredAny={PRD_PLAYERS_ACCESS_ANY}>
        {Number.isFinite(id) && id > 0 ? (
          <PlayerDetailConsole playerId={id} />
        ) : (
          <InvalidPlayerId />
        )}
      </AdminPermissionGate>
    </ModuleScaffold>
  );
}
