<script lang="ts">
import { m } from '$lib/paraglide/messages.js';
import PersonMergePanel from '../PersonMergePanel.svelte';

let {
	person,
	form
}: {
	person: { id: string; firstName?: string | null; lastName: string; displayName: string };
	form?: { mergeError?: string } | null;
} = $props();

let open = $state(false);
</script>

<div class="mt-8 overflow-hidden rounded-sm border border-red-200 bg-surface shadow-sm">
	<button
		type="button"
		onclick={() => (open = !open)}
		class="flex w-full items-center justify-between px-6 py-4 text-left"
		aria-expanded={open}
	>
		<span class="text-sm font-bold tracking-widest text-red-600 uppercase">
			{m.person_danger_zone_heading()}
		</span>
		<svg
			class="h-4 w-4 text-red-400 transition-transform {open ? 'rotate-180' : ''}"
			fill="none"
			stroke="currentColor"
			viewBox="0 0 24 24"
			aria-hidden="true"
		>
			<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
		</svg>
	</button>

	{#if open}
		<div class="border-t border-red-100 px-6 py-4">
			{#key person.id}
				<PersonMergePanel person={person} form={form} />
			{/key}
		</div>
	{/if}
</div>
