{"version":3,"file":"useMarkUnreadHandler.mjs","names":[],"sources":["../../../../../src/components/Message/hooks/useMarkUnreadHandler.ts"],"sourcesContent":["import { validateAndGetMessage } from '../utils';\nimport { useChannel } from '../../../context';\n\nimport type { LocalMessage } from 'stream-chat';\nimport type { ReactEventHandler } from '../types';\n\nexport type MarkUnreadHandlerNotifications = {\n  getErrorNotification?: (message: LocalMessage) => string;\n  getSuccessNotification?: (message: LocalMessage) => string;\n  notify?: (notificationText: string, type: 'success' | 'error') => void;\n};\n\nexport const useMarkUnreadHandler = (\n  message?: LocalMessage,\n  notifications: MarkUnreadHandlerNotifications = {},\n): ReactEventHandler => {\n  const { getSuccessNotification, notify } = notifications;\n\n  const channel = useChannel();\n\n  return async (event) => {\n    event.preventDefault();\n    if (!message?.id) {\n      throw new Error('Mark unread handler does not have access to message id');\n    }\n\n    // Request failures propagate so the caller can report them; `notify` only reports success.\n    await channel.markUnread({ message_id: message.id });\n    if (!notify) return;\n    const successMessage =\n      getSuccessNotification && validateAndGetMessage(getSuccessNotification, [message]);\n    if (successMessage) notify(successMessage, 'success');\n  };\n};\n"],"mappings":";;;AAYA,IAAa,wBACX,SACA,gBAAgD,CAAC,MAC3B;CACtB,MAAM,EAAE,wBAAwB,WAAW;CAE3C,MAAM,UAAU,WAAW;CAE3B,OAAO,OAAO,UAAU;EACtB,MAAM,eAAe;EACrB,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,wDAAwD;EAI1E,MAAM,QAAQ,WAAW,EAAE,YAAY,QAAQ,GAAG,CAAC;EACnD,IAAI,CAAC,QAAQ;EACb,MAAM,iBACJ,0BAA0B,sBAAsB,wBAAwB,CAAC,OAAO,CAAC;EACnF,IAAI,gBAAgB,OAAO,gBAAgB,SAAS;CACtD;AACF"}