{"version":3,"file":"AttachmentUploadedSizeIndicator.mjs","names":[],"sources":["../../../../src/components/Loading/AttachmentUploadedSizeIndicator.tsx"],"sourcesContent":["import React from 'react';\nimport { resolveAttachmentFileSize, resolveAttachmentFullByteSize } from 'stream-chat';\n\nimport { useComponentContext } from '../../context';\nimport { FileSizeIndicator as DefaultFileSizeIndicator } from '../Attachment/components/FileSizeIndicator';\nimport { UploadedSizeIndicator as DefaultUploadedSizeIndicator } from './UploadedSizeIndicator';\n\nexport type AttachmentUploadedSizeIndicatorProps = {\n  /**\n   * Live progress that overrides `localMetadata.uploadProgress`. Pass it for an attachment\n   * carried by a message: the stored value is a snapshot from composition, while\n   * `client.uploadManager` keeps reporting.\n   */\n  uploadProgress?: number;\n  attachment: {\n    custom?: { file_size?: number | string } | null;\n    file_size?: number | string;\n    localMetadata?: {\n      file?: { size?: unknown };\n      uploadProgress?: number;\n      uploadState?: string;\n    } | null;\n  };\n};\n\nexport const AttachmentUploadedSizeIndicator = ({\n  attachment,\n  uploadProgress: liveUploadProgress,\n}: AttachmentUploadedSizeIndicatorProps) => {\n  const {\n    FileSizeIndicator = DefaultFileSizeIndicator,\n    UploadedSizeIndicator = DefaultUploadedSizeIndicator,\n  } = useComponentContext();\n  const { uploadState } = attachment.localMetadata ?? {};\n  const uploadProgress = liveUploadProgress ?? attachment.localMetadata?.uploadProgress;\n  const fullBytes = resolveAttachmentFullByteSize(attachment);\n  const uploaded =\n    uploadProgress !== undefined && fullBytes !== undefined\n      ? Math.round((uploadProgress / 100) * fullBytes)\n      : undefined;\n\n  if (uploadState === 'uploading' && uploaded !== undefined && fullBytes !== undefined) {\n    return <UploadedSizeIndicator fullBytes={fullBytes} uploadedBytes={uploaded} />;\n  }\n\n  if (uploadState === 'finished') {\n    return <FileSizeIndicator fileSize={resolveAttachmentFileSize(attachment)} />;\n  }\n\n  return null;\n};\n"],"mappings":";;;;;;;AAyBA,IAAa,mCAAmC,EAC9C,YACA,gBAAgB,yBAC0B;CAC1C,MAAM,EACJ,mBAAA,sBAAoB,mBACpB,uBAAA,0BAAwB,0BACtB,oBAAoB;CACxB,MAAM,EAAE,gBAAgB,WAAW,iBAAiB,CAAC;CACrD,MAAM,iBAAiB,sBAAsB,WAAW,eAAe;CACvE,MAAM,YAAY,8BAA8B,UAAU;CAC1D,MAAM,WACJ,mBAAmB,KAAA,KAAa,cAAc,KAAA,IAC1C,KAAK,MAAO,iBAAiB,MAAO,SAAS,IAC7C,KAAA;CAEN,IAAI,gBAAgB,eAAe,aAAa,KAAA,KAAa,cAAc,KAAA,GACzE,OAAO,oBAAC,yBAAD;EAAkC;EAAW,eAAe;CAAW,CAAA;CAGhF,IAAI,gBAAgB,YAClB,OAAO,oBAAC,qBAAD,EAAmB,UAAU,0BAA0B,UAAU,EAAI,CAAA;CAG9E,OAAO;AACT"}