"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 _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const MediaMessage = ({
  mimeType,
  location,
  messageText,
  message
}) => {
  if (mimeType) {
    switch (true) {
      case mimeType.startsWith('image/'):
        return /*#__PURE__*/(0, _jsxRuntime.jsx)(_MessageImage.default, {
          fileName: message?.fileName || '000132001',
          fileURL: messageText || '',
          mimetype: mimeType
        });
      case mimeType.startsWith('video/'):
        return /*#__PURE__*/(0, _jsxRuntime.jsx)(_VideoMessage.default, {
          fileName: message?.fileName || '000132001',
          fileURL: location || '',
          mimetype: mimeType
        });
      case mimeType.startsWith('audio/'):
        {
          return /*#__PURE__*/(0, _jsxRuntime.jsx)(_AudioMessage.default, {
            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__*/(0, _jsxRuntime.jsx)(_AudioMessage.default, {
                src: location || ''
              });
            }
          }
          return /*#__PURE__*/(0, _jsxRuntime.jsx)(_UnsupportedType.default, {
            fileURL: location ? location : '',
            fileName: fileName,
            mimetype: mimeType
          });
        }
    }
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
    children: "Unsupported media type"
  });
};
var _default = exports.default = MediaMessage;
//# sourceMappingURL=MediaMessage.js.map