<!--
Phase 27 Report View — battles section. Each row is a link into the
Battle Viewer at `/games/<id>/battle/<uuid>?turn=<turn>` where
`turn` follows the current report's turn so history-mode views land
on the right battle. Phase 23 rendered the same rows as inactive
monospace `<span>`; the rewire here is the one-liner the Phase 23
decision log called out.
-->
<script lang="ts">
	import { getContext } from "svelte";
	import { page } from "$app/state";

	import { i18n } from "$lib/i18n/index.svelte";
	import {
		RENDERED_REPORT_CONTEXT_KEY,
		type RenderedReportSource,
	} from "$lib/rendered-report.svelte";

	const rendered = getContext<RenderedReportSource | undefined>(
		RENDERED_REPORT_CONTEXT_KEY,
	);
	const report = $derived(rendered?.report ?? null);
	const battles = $derived(report?.battles ?? []);
	const gameId = $derived(page.params.id ?? "");
	const turn = $derived(report?.turn ?? 0);
</script>

<section
	id="report-battles"
	class="grid-section"
	data-testid="report-section-battles"
>
	<h2>{i18n.t("game.report.section.battles.title")}</h2>

	{#if report === null}
		<p class="status">{i18n.t("game.report.loading")}</p>
	{:else if battles.length === 0}
		<p class="status" data-testid="battles-empty">
			{i18n.t("game.report.section.battles.empty")}
		</p>
	{:else}
		<ul class="ids" data-testid="battles-list">
			{#each battles as b (b.id)}
				<li>
					<span class="label">
						{i18n.t("game.report.section.battles.id_label")}
					</span>
					<a
						class="uuid"
						href={`/games/${gameId}/battle/${b.id}?turn=${turn}`}
						data-testid="report-battle-row"
						data-id={b.id}
					>{b.id}</a>
				</li>
			{/each}
		</ul>
	{/if}
</section>

<style>
	.grid-section h2 {
		margin: 0 0 0.5rem;
		font-size: 1.05rem;
		color: #e8eaf6;
	}
	.status {
		margin: 0;
		color: #888;
		font-size: 0.9rem;
	}
	.ids {
		list-style: none;
		padding: 0;
		margin: 0;
		display: flex;
		flex-direction: column;
		gap: 0.3rem;
		font-size: 0.85rem;
	}
	.ids li {
		display: flex;
		align-items: baseline;
		gap: 0.6rem;
	}
	.label {
		color: #aab;
		text-transform: uppercase;
		letter-spacing: 0.04em;
		font-size: 0.7rem;
	}
	.uuid {
		color: #cfd7ff;
		font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
		text-decoration: underline;
		text-underline-offset: 2px;
	}
	.uuid:hover {
		color: #ffffff;
	}
</style>
