{"version":3,"file":"RemoveAttachmentPreviewButton.mjs","names":[],"sources":["../../../../src/components/MessageComposer/RemoveAttachmentPreviewButton.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { Button } from '../Button';\nimport React, { type ComponentProps } from 'react';\nimport { useComponentContextIcons, useTranslationContext } from '../../context';\nimport type { AttachmentLoadingState } from 'stream-chat';\n\n/** Upload states in which the request is still running, so removing also cancels it. */\nconst IN_FLIGHT_UPLOAD_STATES: AttachmentLoadingState[] = ['pending', 'uploading'];\n\nexport const RemoveAttachmentPreviewButton = ({\n  className,\n  uploadState,\n  ...props\n}: ComponentProps<'button'> & {\n  uploadState?: AttachmentLoadingState;\n}) => {\n  const { IconXmarkSmall } = useComponentContextIcons();\n  const { t } = useTranslationContext();\n\n  // The button stays actionable mid-upload: `removeAttachments` forwards to\n  // `UploadManager.deleteUploadRecord`, which aborts the request through its `AbortController`.\n  // The `uploadState: 'failed'` update that follows is a no-op because `updateAttachment` ignores\n  // an ID that is no longer in state.\n  const isInFlight = !!uploadState && IN_FLIGHT_UPLOAD_STATES.includes(uploadState);\n\n  return (\n    <Button\n      aria-label={\n        isInFlight\n          ? t(\n              'messageComposer.removeAttachmentPreviewButton.cancelUpload.ariaLabel',\n              'Cancel upload',\n            )\n          : t(\n              'messageComposer.removeAttachmentPreview.removeAttachment.ariaLabel',\n              'Remove attachment',\n            )\n      }\n      circular\n      className={clsx('str-chat__attachment-preview__remove-button', className)}\n      data-testid='preview-item-delete-button'\n      {...props}\n    >\n      <IconXmarkSmall />\n    </Button>\n  );\n};\n"],"mappings":";;;;;;;;AAOA,IAAM,0BAAoD,CAAC,WAAW,WAAW;AAEjF,IAAa,iCAAiC,EAC5C,WACA,aACA,GAAG,YAGC;CACJ,MAAM,EAAE,mBAAmB,yBAAyB;CACpD,MAAM,EAAE,MAAM,sBAAsB;CAQpC,OACE,oBAAC,QAAD;EACE,cAJe,CAAC,CAAC,eAAe,wBAAwB,SAAS,WAAW,IAMtE,EACE,wEACA,eACF,IACA,EACE,sEACA,mBACF;EAEN,UAAA;EACA,WAAW,KAAK,+CAA+C,SAAS;EACxE,eAAY;EACZ,GAAI;YAEJ,oBAAC,gBAAD,CAAiB,CAAA;CACX,CAAA;AAEZ"}