<script lang="ts">
	import { Button } from "$lib/components/ui/button";
	import * as Dialog from "$lib/components/ui/dialog";
	import { Separator } from "$lib/components/ui/separator";
	import type { Country } from "$lib/api/dashboard/reference_data/countries";

	let {
		open = $bindable(false),
		item
	}: {
		open: boolean;
		item: Country | null;
	} = $props();

	function handleOpenChange(newOpen: boolean) {
		open = newOpen;
	}
</script>

<Dialog.Root bind:open onOpenChange={handleOpenChange}>
	<Dialog.Content class="sm:max-w-[600px]">
		<Dialog.Header>
			<Dialog.Title>Detalles del País</Dialog.Title>
			<Dialog.Description>
				Información completa del país
			</Dialog.Description>
		</Dialog.Header>

		{#if item}
			<div class="space-y-4 py-4">
				<div class="grid grid-cols-3 gap-4">
					<div class="space-y-2">
						<span class="text-sm font-medium text-muted-foreground">Clave M3</span>
						<code class="block relative rounded bg-muted px-2 py-1 font-mono text-sm">
							{item.m3_key}
						</code>
					</div>
					
					<div class="space-y-2">
						<span class="text-sm font-medium text-muted-foreground">Clave MX</span>
						<code class="block relative rounded bg-muted px-2 py-1 font-mono text-sm">
							{item.mex_key}
						</code>
					</div>
					
					<div class="space-y-2">
						<span class="text-sm font-medium text-muted-foreground">Clave AME</span>
						<code class="block relative rounded bg-muted px-2 py-1 font-mono text-sm">
							{item.ame_key}
						</code>
					</div>
				</div>
				<Separator />

				<div class="space-y-2">
					<div class="flex flex-col gap-2">
						<span class="text-sm font-medium text-muted-foreground">Descripción en Español</span>
						<p class="text-sm">{item.description_es}</p>
					</div>
					<Separator />
				</div>

				<div class="space-y-2">
					<div class="flex flex-col gap-2">
						<span class="text-sm font-medium text-muted-foreground">Descripción en Inglés</span>
						<p class="text-sm">{item.description_en}</p>
					</div>
					<Separator />
				</div>
			</div>
		{/if}

		<Dialog.Footer>
			<Button variant="outline" onclick={() => (open = false)}>
				Cerrar
			</Button>
		</Dialog.Footer>
	</Dialog.Content>
</Dialog.Root>
