import type { CommunicationRequest } from 'fhir/r4'; // Unread messages across the listed conversations; undefined when the listing failed, because unread is then unknown. export const inboxUnreadCount = ( threads: CommunicationRequest[], unreadFor: (threadId: string) => number, listingFailed: boolean, ): number | undefined => listingFailed ? undefined : threads.reduce((total, request) => total + unreadFor(request.id as string), 0); // The Inbox tab carries a number only when there is unread to report: never at zero, never while unknown. export const inboxTabLabel = (label: string, unread: number | undefined): string => unread !== undefined && unread > 0 ? `${label} (${unread})` : label;