import { b as _extends } from '../_rollupPluginBabelHelpers-4f8ebde4.js';
import React__default, { useState } from 'react';
import Icon, { IconTypes, IconColors } from './Icon.js';
import ImageRenderer from './ImageRenderer.js';
import { h as getClassName, p as isVideoMessage, o as isGifMessage, C as isSentMessage } from '../index-eefb44ba.js';
import { n as noop } from '../utils-b53fe532.js';
import { u as useLongPress } from '../useLongPress-cb2d23be.js';
import 'prop-types';
import '../utils/message/getOutgoingMessageState.js';
import '../MediaQueryContext-b4904a2e.js';

function ThumbnailMessageItemBody(_ref) {
  var _thumbnails$, _message$reactions$le, _message$reactions;
  let {
    className = '',
    message,
    isByMe = false,
    mouseHover = false,
    isReactionEnabled = false,
    showFileViewer = noop,
    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);
  const onClickHandler = useLongPress({
    onLongPress: noop,
    onClick: () => {
      if (isSentMessage(message)) {
        showFileViewer === null || showFileViewer === void 0 ? void 0 : showFileViewer(true);
      }
    }
  });
  return /*#__PURE__*/React__default.createElement("div", _extends({
    className: getClassName([className, 'sendbird-thumbnail-message-item-body', isByMe ? 'outgoing' : 'incoming', mouseHover ? 'mouse-hover' : '', isReactionEnabled && ((_message$reactions$le = (_message$reactions = message.reactions) === null || _message$reactions === void 0 ? void 0 : _message$reactions.length) !== null && _message$reactions$le !== void 0 ? _message$reactions$le : 0) > 0 ? 'reactions' : ''])
  }, onClickHandler), /*#__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_
    })
  }), 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
