<script lang="ts">
import { m } from '$lib/paraglide/messages.js';
import DateInputWithPrecision from '$lib/shared/primitives/DateInputWithPrecision.svelte';
import type { DatePrecision } from '$lib/shared/utils/documentDate';

// Only DAY / MONTH / YEAR are offered for life dates: RANGE and SEASON make no
// sense for a birth or death, and APPROX stays display-only for legacy imports (#773).
let {
	name,
	legend,
	precisionLabel,
	initialIso = '',
	initialPrecision = null
}: {
	name: string;
	legend: string;
	precisionLabel: string;
	initialIso?: string | null;
	initialPrecision?: string | null;
} = $props();

const precisions: { value: DatePrecision; label: string }[] = $derived([
	{ value: 'DAY', label: m.person_precision_day() },
	{ value: 'MONTH', label: m.person_precision_month() },
	{ value: 'YEAR', label: m.person_precision_year() }
]);
const hint = $derived(`${m.person_precision_hint()} · ${m.person_date_placeholder_hint()}`);
</script>

<DateInputWithPrecision
	name={name}
	legend={legend}
	precisionLabel={precisionLabel}
	precisions={precisions}
	hint={hint}
	initialIso={initialIso}
	initialPrecision={initialPrecision}
	selectClass="bg-surface"
/>
