<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 { InvoiceType } from "$lib/api/dashboard/reference_data/invoice_types";

	let {
		open = $bindable(false),
		item
	}: {
		open: boolean;
		item: InvoiceType | 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 Tipo de Factura</Dialog.Title>
			<Dialog.Description>
				Información completa del tipo de factura
			</Dialog.Description>
		</Dialog.Header>

		{#if item}
			<div class="space-y-4 py-4">
				<div class="space-y-2">
					<div class="flex items-center justify-between">
						<span class="text-sm font-medium text-muted-foreground">Clave</span>
						<code class="relative rounded bg-muted px-2 py-1 font-mono text-sm font-semibold">
							{item.key}
						</code>
					</div>
					<Separator />
				</div>

				<div class="space-y-2">
					<div class="flex items-center justify-between">
						<span class="text-sm font-medium text-muted-foreground">Descripción</span>
						<span class="text-sm">{item.description}</span>
					</div>
					<Separator />
				</div>

				{#if item.type}
					<div class="space-y-2">
						<div class="flex items-center justify-between">
							<span class="text-sm font-medium text-muted-foreground">Tipo</span>
							<span class="text-sm">{item.type}</span>
						</div>
						<Separator />
					</div>
				{/if}

				{#if item.note}
					<div class="space-y-2">
						<div class="flex flex-col gap-2">
							<span class="text-sm font-medium text-muted-foreground">Nota / Observación</span>
							<p class="text-sm text-muted-foreground">{item.note}</p>
						</div>
						<Separator />
					</div>
				{/if}
			</div>
		{/if}

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