"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 { jsx as _jsx } from "react/jsx-runtime";
const MediaMessage = ({
  mimeType,
  location,
  messageText,
  message
}) => {
  if (mimeType) {
    switch (true) {
      case mimeType.startsWith('image/'):
        return /*#__PURE__*/_jsx(CustomMessageImage, {
          fileName: message?.fileName || '000132001',
          fileURL: messageText || '',
          mimetype: mimeType
        });
      case mimeType.startsWith('video/'):
        return /*#__PURE__*/_jsx(CustomMessageVideo, {
          fileName: message?.fileName || '000132001',
          fileURL: location || '',
          mimetype: mimeType
        });
      case mimeType.startsWith('audio/'):
        {
          return /*#__PURE__*/_jsx(AudioMessage, {
            src: location || ''
          });
        }
      default:
        {
          // Many backends tag binary payloads (PDFs, DOCX, archives) as
          // application/octet-stream; sniff the filename extension for the
          // legitimate audio case before falling through to FileDownload.
          const fileName = message?.fileName || location?.split('/')?.pop() || 'MediaFile';
          if (mimeType.includes('application/octet-stream')) {
            if (/\.(mp3|m4a|wav|aac|ogg|flac)$/i.test(fileName)) {
              return /*#__PURE__*/_jsx(AudioMessage, {
                src: location || ''
              });
            }
          }
          return /*#__PURE__*/_jsx(FileDownload, {
            fileURL: location ? location : '',
            fileName: fileName,
            mimetype: mimeType
          });
        }
    }
  }
  return /*#__PURE__*/_jsx(Text, {
    children: "Unsupported media type"
  });
};
export default MediaMessage;
//# sourceMappingURL=MediaMessage.js.map