import type { ThreadListingState } from '../../services'; // Search filters rows without changing listing authority or completeness. // Refused, pending, unknown, failed and partial remain distinct, in that priority order. export type ThreadListingRank = 'refused' | 'pending' | 'unknown' | 'failed' | 'partial' | 'complete'; export interface ThreadListingRankInput { state: ThreadListingState; /** The current acting-as refusal. Staff have no helper grant to refuse, so this is patient-only. */ refused?: boolean; /** A no-practice helper's own grant: 'pending' while it is read, 'unknown' when it could not be. */ helperGrantState?: 'pending' | 'unknown'; } export const rankThreadListing = ({ state, refused, helperGrantState }: ThreadListingRankInput): ThreadListingRank => { if (refused) return 'refused'; if (helperGrantState === 'pending' || state === 'pending') return 'pending'; if (state === 'unknown') return 'unknown'; if (state === 'failed' || helperGrantState === 'unknown') return 'failed'; if (state === 'partial') return 'partial'; return 'complete'; }; /** The inline notice to show beside rows already on screen. `undefined` for a known-complete list. */ export const rowsNoticeFor = (rank: ThreadListingRank): { text: string; retry: boolean } | undefined => { switch (rank) { case 'pending': return { text: 'Checking your access to these messages', retry: false }; case 'unknown': return { text: 'Checking for new conversations', retry: false }; case 'failed': return { text: 'Some conversations could not be loaded. What is shown may be out of date.', retry: true }; case 'partial': return { text: 'Some conversations could not be loaded.', retry: true }; default: return undefined; } };