{"version":3,"file":"UploadButton.mjs","names":[],"sources":["../../../../src/components/ReactFileUtilities/UploadButton.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { nanoid } from 'nanoid';\nimport type { ComponentProps } from 'react';\nimport React, { forwardRef, useCallback, useMemo } from 'react';\n\nimport { useHandleFileChangeWrapper } from './utils';\nimport { useMessageComposerContext, useTranslationContext } from '../../context';\nimport { useMessageComposerController } from '../MessageComposer/hooks/useMessageComposerController';\nimport { useStateStore } from '../../store';\nimport type { MessageComposerConfig } from 'stream-chat';\nimport type { PartialSelected } from '../../types/types';\n\nconst attachmentManagerConfigStateSelector = (state: MessageComposerConfig) => ({\n  acceptedFiles: state.attachments.acceptedFiles,\n  maxNumberOfFilesPerMessage: state.attachments.maxNumberOfFilesPerMessage,\n});\n\nexport type FileInputProps = {\n  onFileChange: (files: Array<File>) => void;\n  resetOnChange?: boolean;\n} & Omit<ComponentProps<'input'>, 'type' | 'onChange'>;\n\nexport const FileInput = forwardRef(function FileInput(\n  { onFileChange, resetOnChange = true, ...rest }: FileInputProps,\n  ref: React.ForwardedRef<HTMLInputElement>,\n) {\n  const handleInputChange = useHandleFileChangeWrapper(resetOnChange, onFileChange);\n\n  return <input onChange={handleInputChange} ref={ref} type='file' {...rest} />;\n});\n\nexport const UploadFileInput = forwardRef(function UploadFileInput(\n  {\n    className,\n    onFileChange: onFileChangeCustom,\n    ...props\n  }: PartialSelected<FileInputProps, 'onFileChange'>,\n  ref: React.ForwardedRef<HTMLInputElement>,\n) {\n  const { t } = useTranslationContext();\n  const { textareaRef } = useMessageComposerContext();\n  const messageComposer = useMessageComposerController();\n  const { attachmentManager } = messageComposer;\n  const { acceptedFiles, maxNumberOfFilesPerMessage } = useStateStore(\n    messageComposer.configState,\n    attachmentManagerConfigStateSelector,\n  );\n  const id = useMemo(() => nanoid(), []);\n\n  const onFileChange = useCallback(\n    (files: Array<File>) => {\n      attachmentManager.uploadFiles(files);\n      textareaRef.current?.focus();\n      onFileChangeCustom?.(files);\n    },\n    [onFileChangeCustom, attachmentManager, textareaRef],\n  );\n\n  return (\n    <FileInput\n      accept={acceptedFiles?.join(',')}\n      aria-label={t('fileUpload.uploadButton.fileUpload.ariaLabel', 'File upload')}\n      data-testid='file-input'\n      id={id}\n      multiple={maxNumberOfFilesPerMessage > 1}\n      {...props}\n      className={clsx('str-chat__file-input', className)}\n      onFileChange={onFileChange}\n      ref={ref}\n    />\n  );\n});\n"],"mappings":";;;;;;;;;;AAYA,IAAM,wCAAwC,WAAkC;CAC9E,eAAe,MAAM,YAAY;CACjC,4BAA4B,MAAM,YAAY;AAChD;AAOA,IAAa,YAAY,WAAW,SAAS,UAC3C,EAAE,cAAc,gBAAgB,MAAM,GAAG,QACzC,KACA;CAGA,OAAO,oBAAC,SAAD;EAAO,UAFY,2BAA2B,eAAe,YAE5C;EAAwB;EAAK,MAAK;EAAO,GAAI;CAAO,CAAA;AAC9E,CAAC;AAED,IAAa,kBAAkB,WAAW,SAAS,gBACjD,EACE,WACA,cAAc,oBACd,GAAG,SAEL,KACA;CACA,MAAM,EAAE,MAAM,sBAAsB;CACpC,MAAM,EAAE,gBAAgB,0BAA0B;CAClD,MAAM,kBAAkB,6BAA6B;CACrD,MAAM,EAAE,sBAAsB;CAC9B,MAAM,EAAE,eAAe,+BAA+B,cACpD,gBAAgB,aAChB,oCACF;CACA,MAAM,KAAK,cAAc,OAAO,GAAG,CAAC,CAAC;CAErC,MAAM,eAAe,aAClB,UAAuB;EACtB,kBAAkB,YAAY,KAAK;EACnC,YAAY,SAAS,MAAM;EAC3B,qBAAqB,KAAK;CAC5B,GACA;EAAC;EAAoB;EAAmB;CAAW,CACrD;CAEA,OACE,oBAAC,WAAD;EACE,QAAQ,eAAe,KAAK,GAAG;EAC/B,cAAY,EAAE,gDAAgD,aAAa;EAC3E,eAAY;EACR;EACJ,UAAU,6BAA6B;EACvC,GAAI;EACJ,WAAW,KAAK,wBAAwB,SAAS;EACnC;EACT;CACN,CAAA;AAEL,CAAC"}