"use strict";

import React from 'react';
import FileDownload from '../styled/UnsupportedType';
import CustomMessageImage from '../styled/MessageImage';
import CustomMessageVideo from '../styled/VideoMessage';
import AudioMessage from '../styled/AudioMessage';
import { Text } from 'react-native';
import { deriveDisplayFilename, isLikelyAudio } from '../../helpers/mimeToExtension';
import { jsx as _jsx } from "react/jsx-runtime";
const MediaMessage = ({
  mimeType,
  location,
  messageText,
  message,
  isUser
}) => {
  if (mimeType) {
    const displayName = deriveDisplayFilename({
      fileName: message?.fileName,
      originalName: message?.originalName,
      url: location || messageText,
      mime: mimeType
    });
    switch (true) {
      case mimeType.startsWith('image/'):
        return /*#__PURE__*/_jsx(CustomMessageImage, {
          fileName: displayName,
          fileURL: messageText || '',
          mimetype: mimeType
        });
      case mimeType.startsWith('video/'):
        return /*#__PURE__*/_jsx(CustomMessageVideo, {
          fileName: displayName,
          fileURL: location || '',
          mimetype: mimeType
        });
      case mimeType.startsWith('audio/'):
        {
          return /*#__PURE__*/_jsx(AudioMessage, {
            src: location || ''
          });
        }
      default:
        {
          // Some senders (notably the web app's voice-message uploader)
          // ship audio as `application/octet-stream` with no audio file
          // extension. `isLikelyAudio` recognises those via the URL path,
          // filename, or voice-message naming hints (voicemail-,
          // voice-note-, recording-, …) so we still render the AudioMessage
          // player instead of falling through to the generic FileDownload
          // card (where the voicemail rendered as a broken `.bin`
          // attachment). Customer-reported #9 voicemail fix.
          if (isLikelyAudio(mimeType, displayName, location)) {
            return /*#__PURE__*/_jsx(AudioMessage, {
              src: location || ''
            });
          }
          return /*#__PURE__*/_jsx(FileDownload, {
            fileURL: location ? location : '',
            fileName: displayName,
            mimetype: mimeType,
            isUser: isUser
          });
        }
    }
  }
  return /*#__PURE__*/_jsx(Text, {
    children: "Unsupported media type"
  });
};
export default MediaMessage;
//# sourceMappingURL=MediaMessage.js.map