import React__default, { useState } from 'react';
import Icon, { IconTypes, IconColors } from './Icon.js';
import ImageRenderer from './ImageRenderer.js';
import { j as getClassName, u as isSentMessage, q as isVideoMessage, p as isGifMessage } from '../index-dbe0e004.js';
import 'prop-types';
import '../_rollupPluginBabelHelpers-b2d9bfc5.js';
import '../utils/message/getOutgoingMessageState.js';

function ThumbnailMessageItemBody(_ref) {
  var _thumbnails$, _message$reactions;
  let {
    className,
    message,
    isByMe = false,
    mouseHover = false,
    isReactionEnabled = false,
    showFileViewer,
    style = {}
  } = _ref;
  const {
    thumbnails = []
  } = message;
  const thumbnailUrl = thumbnails.length > 0 ? (_thumbnails$ = thumbnails[0]) === null || _thumbnails$ === void 0 ? void 0 : _thumbnails$.url : '';
  const [imageRendered, setImageRendered] = useState(false);
  return /*#__PURE__*/React__default.createElement("div", {
    className: getClassName([className, 'sendbird-thumbnail-message-item-body', isByMe ? 'outgoing' : 'incoming', mouseHover ? 'mouse-hover' : '', isReactionEnabled && (message === null || message === void 0 ? void 0 : (_message$reactions = message.reactions) === null || _message$reactions === void 0 ? void 0 : _message$reactions.length) > 0 ? 'reactions' : '']),
    onClick: () => {
      if (isSentMessage(message)) {
        showFileViewer(true);
      }
    }
  }, /*#__PURE__*/React__default.createElement(ImageRenderer, {
    className: "sendbird-thumbnail-message-item-body__thumbnail",
    url: thumbnailUrl || (message === null || message === void 0 ? void 0 : message.url),
    alt: message === null || message === void 0 ? void 0 : message.type,
    width: (style === null || style === void 0 ? void 0 : style.width) || '360px',
    height: (style === null || style === void 0 ? void 0 : style.height) || '270px',
    onLoad: () => {
      setImageRendered(true);
    },
    placeHolder: style_ => /*#__PURE__*/React__default.createElement("div", {
      className: "sendbird-thumbnail-message-item-body__placeholder",
      style: style_
    }, /*#__PURE__*/React__default.createElement("div", {
      className: "sendbird-thumbnail-message-item-body__placeholder__icon"
    }, /*#__PURE__*/React__default.createElement(Icon, {
      type: isVideoMessage(message) ? IconTypes.PLAY : IconTypes.PHOTO,
      fillColor: IconColors.ON_BACKGROUND_2,
      width: "34px",
      height: "34px"
    })))
  }), isVideoMessage(message) && !thumbnailUrl && !imageRendered && /*#__PURE__*/React__default.createElement("video", {
    className: "sendbird-thumbnail-message-item-body__video"
  }, /*#__PURE__*/React__default.createElement("source", {
    src: message === null || message === void 0 ? void 0 : message.url,
    type: message === null || message === void 0 ? void 0 : message.type
  })), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-thumbnail-message-item-body__image-cover"
  }), (isVideoMessage(message) || isGifMessage(message)) && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-thumbnail-message-item-body__icon-wrapper"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-thumbnail-message-item-body__icon-wrapper__icon"
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: isVideoMessage(message) ? IconTypes.PLAY : IconTypes.GIF,
    fillColor: IconColors.GRAY,
    width: "34px",
    height: "34px"
  }))));
}

export { ThumbnailMessageItemBody as default };
//# sourceMappingURL=ThumbnailMessageItemBody.js.map
