import { formatDatePart, type DatePrecision } from '$lib/shared/utils/documentDate';

/**
 * Formats a relationship's start–end range as plain text, e.g. for a marriage row.
 * Examples (de):
 *   12. Mai 1923 – 13. Juni 1958   (both)
 *   12. Mai 1923                   (start only — no trailing dash)
 *   – 13. Juni 1958                (end only)
 *   ""                             (neither — the caller renders no date line)
 */
export function formatRelationshipDateRange(
	fromDate: string | null | undefined,
	fromDatePrecision: DatePrecision | null | undefined,
	toDate: string | null | undefined,
	toDatePrecision: DatePrecision | null | undefined,
	locale?: string
): string {
	const from = formatDatePart(fromDate, fromDatePrecision, locale);
	const to = formatDatePart(toDate, toDatePrecision, locale);
	if (from && to) {
		return `${from} – ${to}`;
	}
	if (from) {
		return from;
	}
	if (to) {
		return `– ${to}`;
	}
	return '';
}
