"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _UnsupportedType = _interopRequireDefault(require("../styled/UnsupportedType"));
var _MessageImage = _interopRequireDefault(require("../styled/MessageImage"));
var _VideoMessage = _interopRequireDefault(require("../styled/VideoMessage"));
var _AudioMessage = _interopRequireDefault(require("../styled/AudioMessage"));
var _reactNative = require("react-native");
var _mimeToExtension = require("../../helpers/mimeToExtension");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const MediaMessage = ({
  mimeType,
  location,
  messageText,
  message,
  isUser
}) => {
  if (mimeType) {
    const displayName = (0, _mimeToExtension.deriveDisplayFilename)({
      fileName: message?.fileName,
      originalName: message?.originalName,
      url: location || messageText,
      mime: mimeType
    });
    switch (true) {
      case mimeType.startsWith('image/'):
        return /*#__PURE__*/(0, _jsxRuntime.jsx)(_MessageImage.default, {
          fileName: displayName,
          fileURL: messageText || '',
          mimetype: mimeType
        });
      case mimeType.startsWith('video/'):
        return /*#__PURE__*/(0, _jsxRuntime.jsx)(_VideoMessage.default, {
          fileName: displayName,
          fileURL: location || '',
          mimetype: mimeType
        });
      case mimeType.startsWith('audio/'):
        {
          return /*#__PURE__*/(0, _jsxRuntime.jsx)(_AudioMessage.default, {
            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 ((0, _mimeToExtension.isLikelyAudio)(mimeType, displayName, location)) {
            return /*#__PURE__*/(0, _jsxRuntime.jsx)(_AudioMessage.default, {
              src: location || ''
            });
          }
          return /*#__PURE__*/(0, _jsxRuntime.jsx)(_UnsupportedType.default, {
            fileURL: location ? location : '',
            fileName: displayName,
            mimetype: mimeType,
            isUser: isUser
          });
        }
    }
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
    children: "Unsupported media type"
  });
};
var _default = exports.default = MediaMessage;
//# sourceMappingURL=MediaMessage.js.map