import { m } from '$lib/paraglide/messages.js'; export const PERSON_TYPES = ['PERSON', 'INSTITUTION', 'GROUP', 'UNKNOWN'] as const; export type PersonType = (typeof PERSON_TYPES)[number]; export function normalizePersonType(raw: string | undefined | null): PersonType { return raw === 'SKIP' ? 'UNKNOWN' : ((raw ?? 'PERSON') as PersonType); } export type PersonValidationKey = | 'validation_last_name_required' | 'validation_first_name_required'; export function resolveValidationMessage(key: PersonValidationKey): string { return key === 'validation_last_name_required' ? m.validation_last_name_required() : m.validation_first_name_required(); } export function validatePersonFields( personType: string, firstName: string | undefined | null, lastName: string | undefined | null ): PersonValidationKey | null { if (!lastName) return 'validation_last_name_required'; if (personType === 'PERSON' && !firstName) return 'validation_first_name_required'; return null; }