{"version":3,"file":"utils.a11y.mjs","names":[],"sources":["../../../../../src/components/Threads/ThreadList/utils.a11y.ts"],"sourcesContent":["import type { Channel, LocalMessage, StreamChat } from 'stream-chat';\n\nimport type { ChatContextValue } from '../../../context';\nimport type { TranslationContextValue } from '../../../context/TranslationContext';\nimport {\n  type AccessibleLabelConfig,\n  type AccessibleLabelPart,\n  activeLabelPart,\n  composeAccessibleLabel,\n  unreadCountLabelPart,\n} from '../../../a11y/accessibleLabel';\nimport { getDateString } from '../../../i18n/utils';\nimport { convertTimestampToDate } from 'stream-chat';\n\n/**\n * What the label parts read, gathered by `ThreadListItemUI` from the thread state and contexts.\n */\nexport type ThreadListItemLabelData = {\n  /** Whether the row is the active (currently open) thread. */\n  active?: boolean;\n  /** The channel the thread belongs to. */\n  channel?: Channel;\n  client: StreamChat;\n  /** The channel's display name (the thread row's title). */\n  displayTitle?: string;\n  isMessageAIGenerated?: ChatContextValue['isMessageAIGenerated'];\n  /** The most recent reply in the thread. */\n  latestReply?: LocalMessage;\n  /** The thread's parent message; available for custom parts. */\n  parentMessage?: LocalMessage;\n  /**\n   * Preview text of the parent message as read aloud: the visible subtitle's text (from\n   * `useLatestMessagePreview`) with its markdown syntax stripped to words. Ordered-list numbers\n   * stay; bullets, task checkboxes and table separators are dropped. AI-generated text is verbatim.\n   * The default `parentMessage` part reads it.\n   */\n  parentMessagePreview?: string;\n  /** Sender prefix of the parent message preview, when the visible preview shows one. */\n  parentMessageSender?: string;\n  /** Number of participants in the thread. */\n  participantCount?: number;\n  /** Number of replies in the thread. */\n  replyCount?: number;\n  t: TranslationContextValue['t'];\n  tDateTimeParser: TranslationContextValue['tDateTimeParser'];\n  /** The current user's unread reply count for the thread. */\n  unreadCount?: number;\n  userLanguage?: TranslationContextValue['userLanguage'];\n};\n\n/** Produces one segment of the accessible name; return `undefined` or `''` to omit it. */\nexport type ThreadListItemLabelPart = AccessibleLabelPart<ThreadListItemLabelData>;\n\n/**\n * The default label parts, each overridable via {@link ThreadListItemLabelConfig.parts}. The active\n * state is part of the name because `aria-selected` is not reliably spoken for an option with a\n * custom name; the row keeps `aria-selected` for listbox semantics.\n */\nexport const defaultThreadListItemLabelParts = {\n  active: activeLabelPart,\n  name: ({ displayTitle, t }) =>\n    displayTitle\n      ? t('threadList.chat.ariaLabel', 'Chat: {{ channelName }}', {\n          channelName: displayTitle,\n        })\n      : undefined,\n  // Uses the same preview as the row's subtitle.\n  parentMessage: ({ parentMessagePreview, parentMessageSender, t }) => {\n    if (!parentMessagePreview) return undefined;\n    const preview = parentMessageSender\n      ? `${parentMessageSender}: ${parentMessagePreview}`\n      : parentMessagePreview;\n    return t('threadList.thread.ariaLabel', 'Thread: {{ messagePreview }}', {\n      messagePreview: preview,\n    });\n  },\n  replyCount: ({ replyCount, t }) =>\n    typeof replyCount === 'number' && replyCount > 0\n      ? t('common.replyCount.label', {\n          count: replyCount,\n          defaultValue_one: '1 reply',\n          defaultValue_other: '{{ count }} replies',\n        })\n      : undefined,\n  time: ({ latestReply, t, tDateTimeParser }) => {\n    const createdAt = latestReply?.created_at;\n    if (createdAt == null) return undefined;\n    const when = getDateString({\n      messageCreatedAt: convertTimestampToDate(createdAt)?.toISOString(),\n      t,\n      tDateTimeParser,\n      timestampTranslationKey: 'timestamp.ChannelPreviewTimestamp',\n    });\n    return when\n      ? t('common.lastActivity.ariaLabel', 'Last activity: {{ time }}', {\n          time: String(when),\n        })\n      : undefined;\n  },\n  unreadCount: unreadCountLabelPart,\n} satisfies Record<string, ThreadListItemLabelPart>;\n\n/** Order in which the default parts are assembled. */\nexport const DEFAULT_THREAD_LIST_ITEM_LABEL_ORDER = [\n  'name',\n  'active',\n  'unreadCount',\n  'parentMessage',\n  'replyCount',\n  'time',\n] as const;\n\nexport type ThreadListItemLabelConfig = AccessibleLabelConfig<ThreadListItemLabelData>;\n\n/**\n * Composes the accessible name of a thread list row from named parts, by default in the order of\n * {@link DEFAULT_THREAD_LIST_ITEM_LABEL_ORDER}: name, active, unread count, parent message, reply\n * count, last activity.\n *\n * `ThreadListItemUI` takes an `accessibleLabelConfig` prop, so customizing the label means\n * supplying your own `ThreadListItemUI` through `ComponentContext` and forwarding the config.\n * `parts` merge over {@link defaultThreadListItemLabelParts}: a new key adds a part and a\n * same-named key replaces the default. A part returns its segment, or `undefined` or `''` to be\n * omitted. `order` decides which parts render and in what sequence, so a part missing from it is\n * never rendered. `build` returns the entire string instead. `t` accepts only SDK keys, so a part\n * wraps its own keys in `asDynamicKey` or returns a plain string.\n *\n * ```tsx\n * const accessibleLabelConfig: ThreadListItemLabelConfig = {\n *   parts: {\n *     participants: ({ participantCount }) =>\n *       participantCount ? `${participantCount} participants` : undefined,\n *   },\n *   order: ['name', 'participants', ...DEFAULT_THREAD_LIST_ITEM_LABEL_ORDER.slice(1)],\n * };\n * const MyThreadListItemUI = (props: ThreadListItemUIProps) => (\n *   <ThreadListItemUI {...props} accessibleLabelConfig={accessibleLabelConfig} />\n * );\n * ```\n *\n * @param data - What the label parts read.\n * @param config - Parts, order, separator or `build` overrides.\n * @returns The composed accessible name.\n */\nexport const composeThreadListItemAccessibleLabel = (\n  data: ThreadListItemLabelData,\n  config: ThreadListItemLabelConfig = {},\n): string =>\n  composeAccessibleLabel(\n    data,\n    defaultThreadListItemLabelParts,\n    DEFAULT_THREAD_LIST_ITEM_LABEL_ORDER,\n    config,\n  );\n"],"mappings":";;;;;;;;;AA0DA,IAAa,kCAAkC;CAC7C,QAAQ;CACR,OAAO,EAAE,cAAc,QACrB,eACI,EAAE,6BAA6B,2BAA2B,EACxD,aAAa,aACf,CAAC,IACD,KAAA;CAEN,gBAAgB,EAAE,sBAAsB,qBAAqB,QAAQ;EACnE,IAAI,CAAC,sBAAsB,OAAO,KAAA;EAIlC,OAAO,EAAE,+BAA+B,gCAAgC,EACtE,gBAJc,sBACZ,GAAG,oBAAoB,IAAI,yBAC3B,qBAGJ,CAAC;CACH;CACA,aAAa,EAAE,YAAY,QACzB,OAAO,eAAe,YAAY,aAAa,IAC3C,EAAE,2BAA2B;EAC3B,OAAO;EACP,kBAAkB;EAClB,oBAAoB;CACtB,CAAC,IACD,KAAA;CACN,OAAO,EAAE,aAAa,GAAG,sBAAsB;EAC7C,MAAM,YAAY,aAAa;EAC/B,IAAI,aAAa,MAAM,OAAO,KAAA;EAC9B,MAAM,OAAO,cAAc;GACzB,kBAAkB,uBAAuB,SAAS,CAAC,EAAE,YAAY;GACjE;GACA;GACA,yBAAyB;EAC3B,CAAC;EACD,OAAO,OACH,EAAE,iCAAiC,6BAA6B,EAC9D,MAAM,OAAO,IAAI,EACnB,CAAC,IACD,KAAA;CACN;CACA,aAAa;AACf;;AAGA,IAAa,uCAAuC;CAClD;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,wCACX,MACA,SAAoC,CAAC,MAErC,uBACE,MACA,iCACA,sCACA,MACF"}