{"version":3,"file":"RemindMeSubmenu.mjs","names":[],"sources":["../../../../src/components/MessageActions/RemindMeSubmenu.tsx"],"sourcesContent":["import React from 'react';\nimport {\n  useChatContext,\n  useComponentContextIcons,\n  useMessageContext,\n  useTranslationContext,\n} from '../../context';\nimport { useNotificationApi } from '../Notifications';\nimport {\n  ContextMenuBackButton,\n  ContextMenuButton,\n  ContextMenuHeader,\n  useContextMenuContext,\n} from '../Dialog';\n\nconst getErrorMessage = (error: unknown, fallback: string) =>\n  error instanceof Error && error.message ? error.message : fallback;\n\nconst getNotificationError = (error: unknown): Error | undefined => {\n  if (error instanceof Error) return error;\n  if (typeof error === 'string') return new Error(error);\n  if (error && typeof error === 'object' && 'message' in error) {\n    const message = error.message;\n    if (typeof message === 'string') return new Error(message);\n  }\n  return undefined;\n};\n\nexport const RemindMeSubmenuHeader = () => {\n  const { IconChevronLeft } = useComponentContextIcons();\n  const { t } = useTranslationContext();\n  const { returnToParentMenu } = useContextMenuContext();\n  return (\n    <ContextMenuHeader>\n      <ContextMenuBackButton onClick={returnToParentMenu}>\n        <IconChevronLeft />\n        <span>{t('messageActions.remindMeSubmenu.remindMe.text', 'Remind Me')}</span>\n      </ContextMenuBackButton>\n    </ContextMenuHeader>\n  );\n};\n\nexport const RemindMeSubmenu = () => {\n  const { t } = useTranslationContext();\n  const { client } = useChatContext();\n  const { message } = useMessageContext();\n  const { closeMenu } = useContextMenuContext();\n  const { addNotification } = useNotificationApi();\n  return (\n    <div className='str-chat__message-actions-box__submenu'>\n      {client.reminders.scheduledOffsetsMs.map((offsetMs) => (\n        <ContextMenuButton\n          className='str-chat__message-actions-list-item-button'\n          key={`reminder-offset-option--${offsetMs}`}\n          onClick={async () => {\n            try {\n              await client.reminders.upsertReminder(\n                { message_id: message.id },\n                { remind_at: new Date(new Date().getTime() + offsetMs) },\n              );\n              addNotification({\n                context: {\n                  message,\n                },\n                emitter: 'MessageActions',\n                message: t('common.reminderSet.text', 'Reminder set'),\n                severity: 'success',\n                type: 'api:message:reminder:set:success',\n              });\n            } catch (error) {\n              addNotification({\n                context: {\n                  message,\n                },\n                emitter: 'MessageActions',\n                error: getNotificationError(error),\n                message: getErrorMessage(error, 'Error setting reminder'),\n                severity: 'error',\n                type: 'api:message:reminder:set:failed',\n              });\n            } finally {\n              closeMenu();\n            }\n          }}\n        >\n          {t('duration.remindMe', { milliseconds: offsetMs })}\n        </ContextMenuButton>\n      ))}\n      {/* todo: potential improvement to add a custom option that would trigger rendering modal with custom date picker - we need date picker */}\n    </div>\n  );\n};\n"],"mappings":";;;;;;;;;AAeA,IAAM,mBAAmB,OAAgB,aACvC,iBAAiB,SAAS,MAAM,UAAU,MAAM,UAAU;AAE5D,IAAM,wBAAwB,UAAsC;CAClE,IAAI,iBAAiB,OAAO,OAAO;CACnC,IAAI,OAAO,UAAU,UAAU,OAAO,IAAI,MAAM,KAAK;CACrD,IAAI,SAAS,OAAO,UAAU,YAAY,aAAa,OAAO;EAC5D,MAAM,UAAU,MAAM;EACtB,IAAI,OAAO,YAAY,UAAU,OAAO,IAAI,MAAM,OAAO;CAC3D;AAEF;AAEA,IAAa,8BAA8B;CACzC,MAAM,EAAE,oBAAoB,yBAAyB;CACrD,MAAM,EAAE,MAAM,sBAAsB;CACpC,MAAM,EAAE,uBAAuB,sBAAsB;CACrD,OACE,oBAAC,mBAAD,EAAA,UACE,qBAAC,uBAAD;EAAuB,SAAS;YAAhC,CACE,oBAAC,iBAAD,CAAkB,CAAA,GAClB,oBAAC,QAAD,EAAA,UAAO,EAAE,gDAAgD,WAAW,EAAQ,CAAA,CACvD;IACN,CAAA;AAEvB;AAEA,IAAa,wBAAwB;CACnC,MAAM,EAAE,MAAM,sBAAsB;CACpC,MAAM,EAAE,WAAW,eAAe;CAClC,MAAM,EAAE,YAAY,kBAAkB;CACtC,MAAM,EAAE,cAAc,sBAAsB;CAC5C,MAAM,EAAE,oBAAoB,mBAAmB;CAC/C,OACE,oBAAC,OAAD;EAAK,WAAU;YACZ,OAAO,UAA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