import type { Organization } from 'fhir/r4'; export default function PracticeContactDetails({ organization }: { organization?: Organization | null }) { const contacts = (organization?.telecom ?? []).flatMap((contact) => { const value = contact.value?.trim(); if (!value) return []; if (contact.system === 'phone' && /^\+?[\d\s().-]+$/.test(value)) { const number = value.replace(/[^\d+]/g, ''); return /\d/.test(number) ? [{ href: `tel:${number}`, label: value }] : []; } if (contact.system === 'email' && /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(value)) { return [{ href: `mailto:${value}`, label: value }]; } return []; }); const uniqueContacts = contacts.filter((contact, index) => contacts.findIndex((candidate) => candidate.href === contact.href) === index); if (!uniqueContacts.length) return null; return ( ); }