import type { GuardianInvitationOrigin, InvitedAuthorityScope } from '../../services/RelatedPersonService.tsx'; /** * THE ONE SENTENCE AN INVITATION SAYS, AND THE ONE PLACE IT IS WRITTEN. * * Spencer, 2026-09-01, and the rule underneath it is what makes the copy work rather than the copy * itself: **an invitation cannot know which relationship it is, so it says what the person may DO rather * than naming what they ARE.** * * SO THE RELATIONSHIP FIELD IS NOT READ HERE, AND MUST NOT BE ADDED. It is in the payload and it is * the one thing forbidden: a spouse, an adult child, a lawyer holding power of attorney and a live-in * carer all arrive through this same invitation, **and only one of them is a caregiver.** There is no * noun that is true for all of them, so no noun is used. * * The shipped Family-page copy was the forbidden shape verbatim - *"You've been invited as a * `` caregiver by ``"* - which is why this exists as a function two surfaces call * rather than a string each of them writes. */ export const invitationSentence = ( inviterName: string, grantScope: InvitedAuthorityScope | undefined, origin?: GuardianInvitationOrigin, ): string => { // A staff-witnessed guardian declaration made this invitation, not the child it names, so the child is not its // author. The server sends the relationship only from the verified declaration, never from the link label. if (origin) { const access = grantScope === 'acts-on-their-behalf' ? `view ${inviterName}'s account and clinical records, and act on their behalf` : grantScope === 'view-only' ? `view ${inviterName}'s account and clinical records` : `access ${inviterName}'s account and clinical records`; if (origin.kind === 'unavailable') return `You were invited to ${access}.`; const recorder = origin.practiceName ?? `Staff at ${inviterName}'s practice`; const role = origin.relationship === 'legal-guardian' ? 'legal guardian' : 'parent'; return `${recorder} recorded you as ${inviterName}'s ${role}, as you told them in person. Accepting lets you ${access}.`; } if (grantScope === 'acts-on-their-behalf') { return `${inviterName} invited you to view their account and clinical records, and to act on their behalf.`; } if (grantScope === 'view-only') { return `${inviterName} invited you to view their account and clinical records.`; } /** * THE SCOPE IS UNKNOWN, AND THIS SENTENCE NEITHER CLAIMS NOR DENIES THE ACTING HALF. * * The server answers nothing rather than guessing when it cannot establish the grant. Falling * back to the view-only wording here would undo that on the last line: somebody would agree to a * read-only view and receive the power to act, having read a sentence we wrote. * "access" is true of both grants and enumerates neither. **Understating a consent is the * dangerous direction; saying less than you know is not the same as saying something false.** */ return `${inviterName} invited you to access their account and clinical records.`; };