<!--
Phase 13 mobile bottom-sheet that hosts the planet inspector when
the user is on the map view on a small screen. Desktop and tablet
breakpoints already render the inspector inside the sidebar, so
the sheet is hidden via a media query above 768 px and the
component is only mounted while the active tool is `map` (so it
does not stack on top of the calc / order overlays).

Phase 13 ships the minimal dismissal surface: a close button (`✕`)
that clears the selection. Swipe-to-dismiss and tap-outside-to-
dismiss from the IA section §6 are deferred to a later polish pass.
-->
<script lang="ts">
	import type {
		ReportBombing,
		ReportLocalShipGroup,
		ReportOtherShipGroup,
		ReportPlanet,
		ReportRoute,
		ScienceSummary,
		ShipClassSummary,
	} from "../../api/game-state";
	import { i18n } from "$lib/i18n/index.svelte";
	import { sheetDismiss } from "$lib/ui/sheet-dismiss";
	import Planet from "./planet.svelte";

	type Props = {
		planet: ReportPlanet | null;
		localShipClass: ShipClassSummary[];
		localScience: ScienceSummary[];
		routes: ReportRoute[];
		planets: ReportPlanet[];
		mapWidth: number;
		mapHeight: number;
		localPlayerDrive: number;
		localShipGroups: ReportLocalShipGroup[];
		otherShipGroups: ReportOtherShipGroup[];
		localRace: string;
		bombing?: ReportBombing | null;
		onMap: boolean;
		onClose: () => void;
	};
	let {
		planet,
		localShipClass,
		localScience,
		routes,
		planets,
		mapWidth,
		mapHeight,
		localPlayerDrive,
		localShipGroups,
		otherShipGroups,
		localRace,
		bombing = null,
		onMap,
		onClose,
	}: Props = $props();
</script>

{#if planet !== null && onMap}
	<section
		class="sheet"
		aria-label={i18n.t("game.sidebar.tab.inspector")}
		data-testid="inspector-planet-sheet"
		use:sheetDismiss={{ onDismiss: onClose }}
	>
		<div class="grabber" data-sheet-handle aria-hidden="true"></div>
		<button
			type="button"
			class="close"
			data-testid="inspector-planet-sheet-close"
			aria-label={i18n.t("game.inspector.sheet_close")}
			onclick={onClose}
		>
			✕
		</button>
		<Planet
			{planet}
			{localShipClass}
			{localScience}
			{routes}
			{planets}
			{mapWidth}
			{mapHeight}
			{localPlayerDrive}
			{localShipGroups}
			{otherShipGroups}
			{localRace}
			{bombing}
		/>
	</section>
{/if}

<style>
	.sheet {
		display: none;
	}
	@media (max-width: 767.98px) {
		.sheet {
			display: block;
			position: fixed;
			left: 0;
			right: 0;
			bottom: 3.25rem;
			max-height: calc(100vh - 6rem);
			overflow-y: auto;
			background: var(--color-surface-overlay);
			color: var(--color-text);
			border-top: 1px solid var(--color-border);
			box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
			z-index: 40;
		}
	}
	.grabber {
		display: block;
		width: 2.5rem;
		height: 0.25rem;
		margin: 0.4rem auto 0.2rem;
		border-radius: var(--radius-pill);
		background: var(--color-border-strong);
		touch-action: none;
		cursor: grab;
	}
	.close {
		position: absolute;
		top: 0.4rem;
		right: 0.4rem;
		font: inherit;
		font-size: 1rem;
		padding: 0.2rem 0.55rem;
		background: transparent;
		color: var(--color-text-muted);
		border: 1px solid var(--color-border);
		border-radius: 3px;
		cursor: pointer;
	}
	.close:hover {
		color: var(--color-text);
		border-color: var(--color-accent);
	}
</style>
