{"version":3,"file":"PollCreationDialogControls.mjs","names":[],"sources":["../../../../../src/components/Poll/PollCreationDialog/PollCreationDialogControls.tsx"],"sourcesContent":["import React from 'react';\nimport { flushSync } from 'react-dom';\nimport { useCanCreatePoll } from '../../MessageComposer/hooks/useCanCreatePoll';\nimport { useMessageComposerController } from '../../MessageComposer/hooks/useMessageComposerController';\nimport {\n  useComponentContextIcons,\n  useMessageComposerContext,\n  useTranslationContext,\n} from '../../../context';\nimport clsx from 'clsx';\nimport { Prompt } from '../../Dialog';\nimport { useNotificationApi } from '../../Notifications';\n\nexport type PollCreationDialogControlsProps = {\n  close: () => void;\n};\n\nexport const PollCreationDialogControls = ({\n  close,\n}: PollCreationDialogControlsProps) => {\n  const { IconSend } = useComponentContextIcons();\n  const { t } = useTranslationContext();\n  const { textareaRef } = useMessageComposerContext();\n  const messageComposer = useMessageComposerController();\n  const sendMessage = messageComposer.send;\n  const canCreatePoll = useCanCreatePoll();\n  const { addNotification } = useNotificationApi();\n\n  return (\n    <Prompt.Footer>\n      <Prompt.FooterControls>\n        <Prompt.FooterControlsButtonSecondary\n          className={clsx('str-chat__prompt__footer__controls-button--cancel')}\n          onClick={close}\n          type='button'\n        >\n          {t('common.cancel.label', 'Cancel')}\n        </Prompt.FooterControlsButtonSecondary>\n        <Prompt.FooterControlsButtonPrimary\n          className={clsx('str-chat__prompt__footer__controls-button--submit')}\n          disabled={!canCreatePoll}\n          onClick={async () => {\n            // Close and focus the composer in the same synchronous turn, before the async work.\n            // The focus restorers (react-aria's FocusScope, AttachmentSelector's trigger) act only\n            // when focus fell to <body>, so this avoids a focus blip through the attachment\n            // trigger.\n            flushSync(() => close());\n            textareaRef?.current?.focus();\n            try {\n              await messageComposer.createPoll();\n            } catch {\n              // `createPoll()` already emits an `api:poll:create:failed` notification; the rethrown\n              // error is swallowed to avoid an unhandled rejection. No poll exists, so do not send.\n              return;\n            }\n            // `createPoll()` also returns without a poll when the composition is empty. Sending\n            // then would submit whatever else the composer holds (drafted text) without the poll.\n            if (!messageComposer.pollId) return;\n            // `sendMessage()` never rejects and reports its own failure, so the success\n            // notification is gated on the result. Compared to `'sent'` because `'failed'` and\n            // `'nothing-to-send'` are truthy strings.\n            if ((await sendMessage()) !== 'sent') return;\n            addNotification({\n              // Assertive: focus just returned to the composer, and a polite message would be\n              // read after that focus announcement.\n              ariaLive: 'assertive',\n              emitter: 'PollCreationDialog',\n              message: t('poll.creationDialog.pollSent.text', 'Poll sent'),\n              severity: 'success',\n              type: 'api:poll:create:success',\n            });\n          }}\n          type='submit'\n        >\n          <IconSend />\n          {t('poll.creationDialog.sendPoll.text', 'Send Poll')}\n        </Prompt.FooterControlsButtonPrimary>\n      </Prompt.FooterControls>\n    </Prompt.Footer>\n  );\n};\n"],"mappings":";;;;;;;;;;;;AAiBA,IAAa,8BAA8B,EACzC,YACqC;CACrC,MAAM,EAAE,aAAa,yBAAyB;CAC9C,MAAM,EAAE,MAAM,sBAAsB;CACpC,MAAM,EAAE,gBAAgB,0BAA0B;CAClD,MAAM,kBAAkB,6BAA6B;CACrD,MAAM,cAAc,gBAAgB;CACpC,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,EAAE,oBAAoB,mBAAmB;CAE/C,OACE,oBAAC,OAAO,QAAR,EAAA,UACE,qBAAC,OAAO,gBAAR,EAAA,UAAA,CACE,oBAAC,OAAO,+BAAR;EACE,WAAW,KAAK,mDAAmD;EACnE,SAAS;EACT,MAAK;YAEJ,EAAE,uBAAuB,QAAQ;CACE,CAAA,GACtC,qBAAC,OAAO,6BAAR;EACE,WAAW,KAAK,mDAAmD;EACnE,UAAU,CAAC;EACX,SAAS,YAAY;GAKnB,gBAAgB,MAAM,CAAC;GACvB,aAAa,SAAS,MAAM;GAC5B,IAAI;IACF,MAAM,gBAAgB,WAAW;GACnC,QAAQ;IAGN;GACF;GAGA,IAAI,CAAC,gBAAgB,QAAQ;GAI7B,IAAK,MAAM,YAAY,MAAO,QAAQ;GACtC,gBAAgB;IAGd,UAAU;IACV,SAAS;IACT,SAAS,EAAE,qCAAqC,WAAW;IAC3D,UAAU;IACV,MAAM;GACR,CAAC;EACH;EACA,MAAK;YAlCP,CAoCE,oBAAC,UAAD,CAAW,CAAA,GACV,EAAE,qCAAqC,WAAW,CACjB;GACf,EAAA,CAAA,EACV,CAAA;AAEnB"}