{"version":3,"file":"ReminderNotification.mjs","names":[],"sources":["../../../../src/components/Message/ReminderNotification.tsx"],"sourcesContent":["import React from 'react';\nimport { useComponentContextIcons, useTranslationContext } from '../../context';\nimport { useStateStore } from '../../store';\nimport type { Reminder, ReminderState } from 'stream-chat';\nimport { nsToDate, nsToMs } from 'stream-chat';\n\nexport type ReminderNotificationProps = {\n  reminder?: Reminder;\n};\n\nconst reminderStateSelector = (state: ReminderState) => ({\n  timeLeftMs: state.timeLeftMs,\n});\n\nfunction SavedForLaterContent() {\n  const { IconBookmark } = useComponentContextIcons();\n  const { t } = useTranslationContext();\n  return (\n    <div className='str-chat__message-saved-for-later'>\n      <IconBookmark />\n      <span>{t('common.savedLater.text', 'Saved for later')}</span>\n    </div>\n  );\n}\n\nconst THRESHOLD_RELATIVE_MINUTES = 59;\n\nfunction RemindMeContent({ reminder }: { reminder: Reminder }) {\n  const { IconBell } = useComponentContextIcons();\n  const { t } = useTranslationContext();\n  const { timeLeftMs } = useStateStore(reminder?.state, reminderStateSelector) ?? {};\n\n  const stopRefreshBoundaryMs = reminder?.timer.stopRefreshBoundaryMs;\n  // Nullish, not truthy: `remindAt` is in unix nanoseconds and 0 (the epoch) is a valid value.\n  const stopRefreshTimeStamp =\n    reminder?.remindAt != null && stopRefreshBoundaryMs != null\n      ? nsToMs(reminder.remindAt) + stopRefreshBoundaryMs\n      : undefined;\n\n  const isBehindRefreshBoundary =\n    stopRefreshTimeStamp != null && new Date().getTime() > stopRefreshTimeStamp;\n\n  if (timeLeftMs === null || reminder.remindAt == null) return null;\n\n  const nowMs = Date.now();\n  const remindAtMs = nsToMs(reminder.remindAt);\n  const diffMs = remindAtMs - nowMs;\n  const diffMinutes = Math.abs(diffMs) / (60 * 1000);\n  const useAbsoluteFormat = diffMinutes > THRESHOLD_RELATIVE_MINUTES;\n\n  const renderTime = () => {\n    if (isBehindRefreshBoundary) {\n      if (useAbsoluteFormat) {\n        // More than 59 minutes ago: calendar date and time, e.g. \"Due since Yesterday at 09:30\".\n        return t(\n          'message.reminderNotification.dueSince.label',\n          'Due since {{ dueSince }}',\n          {\n            dueSince: t('timestamp.ReminderNotification', {\n              timestamp:\n                reminder.remindAt != null ? nsToDate(reminder.remindAt) : undefined,\n            }),\n          },\n        );\n      }\n      // Within 59 minutes: relative, e.g. \"Due since 5 minutes ago\".\n      return t(\n        'message.reminderNotification.dueSince.label',\n        'Due since {{ dueSince }}',\n        {\n          dueSince: t('duration.messageReminder', {\n            milliseconds: diffMs,\n          }),\n        },\n      );\n    }\n    if (useAbsoluteFormat) {\n      // More than 59 minutes from now: calendar date and time without a \"Due\" prefix, e.g.\n      // \"Tomorrow at 09:30\".\n      return t('timestamp.ReminderNotification', {\n        timestamp: reminder.remindAt != null ? nsToDate(reminder.remindAt) : undefined,\n      });\n    }\n    // Within 59 minutes: relative, e.g. \"Due in 30 minutes\".\n    return t('message.reminderNotification.due.label', 'Due {{ timeLeft }}', {\n      timeLeft: t('duration.messageReminder', {\n        milliseconds: timeLeftMs,\n      }),\n    });\n  };\n\n  return (\n    <p className='str-chat__message-reminder'>\n      <IconBell />\n      <span>{t('common.reminderSet.text', 'Reminder set')}</span>\n      <span> · </span>\n      <span className='str-chat__message-reminder__time-left'>{renderTime()}</span>\n    </p>\n  );\n}\n\nexport const ReminderNotification = ({ reminder }: ReminderNotificationProps) => {\n  if (!reminder) return null;\n\n  // Nullish, not truthy: `remindAt` is `null` only when the message is saved for later without a\n  // deadline. `0` is a real deadline (the epoch) and must render as an overdue reminder.\n  if (reminder.remindAt == null) {\n    return <SavedForLaterContent />;\n  }\n\n  return <RemindMeContent reminder={reminder} />;\n};\n"],"mappings":";;;;;;;AAUA,IAAM,yBAAyB,WAA0B,EACvD,YAAY,MAAM,WACpB;AAEA,SAAS,uBAAuB;CAC9B,MAAM,EAAE,iBAAiB,yBAAyB;CAClD,MAAM,EAAE,MAAM,sBAAsB;CACpC,OACE,qBAAC,OAAD;EAAK,WAAU;YAAf,CACE,oBAAC,cAAD,CAA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