{"version":3,"file":"chat-receipt.cjs","names":[],"sources":["../../../src/components/Chat/chat-receipt.ts"],"sourcesContent":["import type { ChatMessage, ChatReceipt } from \"./chat-groups\";\n\n/**\n * What the ticks on an outgoing message say.\n *\n * `\"read\"` is the only one that turns them blue, and in a group that means\n * **everyone** has read it — the distinction `status: \"read\"` cannot make.\n */\nexport type ChatReceiptState = \"sending\" | \"sent\" | \"delivered\" | \"read\" | \"failed\";\n\n/**\n * Resolve the tick state of an outgoing message.\n *\n * A group needs three states where a single message has two: sent to the server,\n * delivered to the recipients, read by the recipients. A boolean `status` collapses\n * the middle one, so an app that has per-recipient counts either invents its own\n * glyph or shows a message as read when one person out of nine opened it.\n *\n * The counts win when they are there, and the thresholds are deliberately \"all\":\n * blue ticks in every messenger mean the whole room, and reporting \"read\" for a\n * partial count is the failure that makes people distrust the indicator entirely.\n * A `totalRecipients` of zero — a note to self, a thread whose membership the app\n * does not track — falls back to `status`, because \"read by all of nobody\" is not\n * a claim worth making.\n *\n * `\"failed\"` and `\"sending\"` come from `status` regardless: they are about this\n * side of the wire, and no recipient count exists yet.\n *\n * @param message - The message being rendered.\n * @returns The tick state, or `null` when there is nothing to show.\n */\nexport function resolveReceiptState(message: ChatMessage): ChatReceiptState | null {\n    if (message.status === \"failed\" || message.status === \"sending\") return message.status;\n    const receipt = message.receipt;\n    if (!receipt || receipt.totalRecipients <= 0) return message.status ?? null;\n    if (receipt.readBy >= receipt.totalRecipients) return \"read\";\n    if (receipt.deliveredTo >= receipt.totalRecipients) return \"delivered\";\n    return message.status ?? \"sent\";\n}\n\n/**\n * The sentence a reader gets for a receipt, for the tooltip and the screen reader.\n *\n * Partial counts are spelled out rather than rounded to a state: \"delivered to 3\n * of 9\" is the information the sender actually wants when the ticks are not blue\n * yet, and it is the part a glyph cannot carry.\n *\n * @param receipt - Per-recipient counts.\n * @param strings - Locale strings for the thread.\n * @returns One sentence describing delivery and reading.\n */\nexport function receiptLabel(\n    receipt: ChatReceipt,\n    strings: {\n        deliveredAll: string;\n        deliveredSome: (delivered: number, total: number) => string;\n        readAll: string;\n        readSome: (read: number, total: number) => string;\n    },\n): string {\n    const { deliveredTo, readBy, totalRecipients } = receipt;\n    if (readBy >= totalRecipients) return strings.readAll;\n    if (readBy > 0) return strings.readSome(readBy, totalRecipients);\n    if (deliveredTo >= totalRecipients) return strings.deliveredAll;\n    return strings.deliveredSome(deliveredTo, totalRecipients);\n}\n"],"mappings":"AA+BA,SAAgB,EAAoB,EAA+C,CAC/E,GAAI,EAAQ,SAAW,UAAY,EAAQ,SAAW,UAAW,OAAO,EAAQ,OAChF,IAAM,EAAU,EAAQ,QAIxB,MAHI,CAAC,GAAW,EAAQ,iBAAmB,EAAU,EAAQ,QAAU,KACnE,EAAQ,QAAU,EAAQ,gBAAwB,OAClD,EAAQ,aAAe,EAAQ,gBAAwB,YACpD,EAAQ,QAAU,MAC7B,CAaA,SAAgB,EACZ,EACA,EAMM,CACN,GAAM,CAAE,cAAa,SAAQ,mBAAoB,EAIjD,OAHI,GAAU,EAAwB,EAAQ,QAC1C,EAAS,EAAU,EAAQ,SAAS,EAAQ,CAAe,EAC3D,GAAe,EAAwB,EAAQ,aAC5C,EAAQ,cAAc,EAAa,CAAe,CAC7D"}