'use strict';

var React = require('react');
var ui_Icon = require('./Icon.js');
var ui_Label = require('../index-bff918b2.js');
var ui_ImageRenderer = require('./ImageRenderer.js');
var LocalizationContext = require('../LocalizationContext-6adf6aa8.js');
var index = require('../index-86e680cb.js');
require('prop-types');
require('../stringSet-5157206d.js');
require('../index-6a7f94de.js');
require('../_rollupPluginBabelHelpers-ea66c137.js');
require('../utils/message/getOutgoingMessageState.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

function QuoteMessage(_ref) {
  var _message$sender, _message$sender2, _message, _thumbnails;
  let {
    message,
    userId = '',
    isByMe = false,
    className = '',
    isUnavailable = false,
    onClick
  } = _ref;
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const {
    parentMessage
  } = message;
  const parentMessageSender = parentMessage === null || parentMessage === void 0 ? void 0 : parentMessage.sender;
  const parentMessageSenderNickname = userId === (parentMessageSender === null || parentMessageSender === void 0 ? void 0 : parentMessageSender.userId) ? stringSet.QUOTED_MESSAGE__CURRENT_USER : parentMessageSender === null || parentMessageSender === void 0 ? void 0 : parentMessageSender.nickname;
  const parentMessageUrl = (parentMessage === null || parentMessage === void 0 ? void 0 : parentMessage.url) || '';
  const parentMessageType = parentMessage === null || parentMessage === void 0 ? void 0 : parentMessage.type;
  const currentMessageSenderNickname = userId === (message === null || message === void 0 ? void 0 : (_message$sender = message.sender) === null || _message$sender === void 0 ? void 0 : _message$sender.userId) ? stringSet.QUOTED_MESSAGE__CURRENT_USER : message === null || message === void 0 ? void 0 : (_message$sender2 = message.sender) === null || _message$sender2 === void 0 ? void 0 : _message$sender2.nickname;
  const [isThumbnailLoaded, setThumbnailLoaded] = React.useState(false);
  const uikitFileTypes = index.getUIKitFileTypes();
  const splitFileName = parentMessage !== null && parentMessage !== void 0 && parentMessage.name ? parentMessage.name.split('/') : parentMessageUrl.split('/');
  return /*#__PURE__*/React__default["default"].createElement("div", {
    className: index.getClassName([className, 'sendbird-quote-message', isByMe ? 'outgoing' : 'incoming', isUnavailable ? 'unavailable' : '']),
    key: parentMessage === null || parentMessage === void 0 ? void 0 : parentMessage.messageId,
    onClick: () => {
      if (!isUnavailable && onClick) {
        onClick();
      }
    },
    onTouchEnd: () => {
      if (!isUnavailable && onClick) {
        onClick();
      }
    }
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-quote-message__replied-to"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    className: "sendbird-quote-message__replied-to__icon",
    type: ui_Icon.IconTypes.REPLY,
    fillColor: ui_Icon.IconColors.ON_BACKGROUND_3,
    width: "12px",
    height: "12px"
  }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-quote-message__replied-to__text",
    type: ui_Label.LabelTypography.CAPTION_2,
    color: ui_Label.LabelColors.ONBACKGROUND_3
  }, /*#__PURE__*/React__default["default"].createElement("span", {
    className: "sendbird-quote-message__replied-to__text__nickname"
  }, currentMessageSenderNickname), /*#__PURE__*/React__default["default"].createElement("span", {
    className: "sendbird-quote-message__replied-to__text__text"
  }, stringSet.QUOTED_MESSAGE__REPLIED_TO), /*#__PURE__*/React__default["default"].createElement("span", {
    className: "sendbird-quote-message__replied-to__text__nickname"
  }, parentMessageSenderNickname))), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-quote-message__replied-message"
  }, isUnavailable && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-quote-message__replied-message__text-message"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-quote-message__replied-message__text-message__word",
    type: ui_Label.LabelTypography.BODY_2,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, stringSet.QUOTED_MESSAGE__UNAVAILABLE)), index.isUserMessage(parentMessage) && (parentMessage === null || parentMessage === void 0 ? void 0 : (_message = parentMessage.message) === null || _message === void 0 ? void 0 : _message.length) > 0 && !isUnavailable && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-quote-message__replied-message__text-message"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-quote-message__replied-message__text-message__word",
    type: ui_Label.LabelTypography.BODY_2,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, parentMessage === null || parentMessage === void 0 ? void 0 : parentMessage.message)), index.isVoiceMessage(parentMessage) && parentMessageUrl && !isUnavailable && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-quote-message__replied-message__text-message"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-quote-message__replied-message__text-message__word",
    type: ui_Label.LabelTypography.BODY_2,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, stringSet.VOICE_MESSAGE)), index.isThumbnailMessage(parentMessage) && parentMessageUrl && !isUnavailable && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-quote-message__replied-message__thumbnail-message"
  }, /*#__PURE__*/React__default["default"].createElement(ui_ImageRenderer, {
    className: "sendbird-quote-message__replied-message__thumbnail-message__image",
    url: parentMessageUrl,
    alt: parentMessageType,
    width: "144px",
    height: "108px",
    onLoad: () => setThumbnailLoaded(true),
    defaultComponent: /*#__PURE__*/React__default["default"].createElement("div", {
      className: "sendbird-quote-message__replied-message__thumbnail-message__placeholder"
    }, /*#__PURE__*/React__default["default"].createElement("div", {
      className: "sendbird-quote-message__replied-message__thumbnail-message__placeholder__icon"
    }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
      type: index.isVideo(parentMessageType) ? ui_Icon.IconTypes.PLAY : ui_Icon.IconTypes.PHOTO,
      fillColor: ui_Icon.IconColors.ON_BACKGROUND_2,
      width: "22px",
      height: "22px"
    })))
  }), index.isVideo(parentMessageType) && !((parentMessage === null || parentMessage === void 0 ? void 0 : (_thumbnails = parentMessage.thumbnails) === null || _thumbnails === void 0 ? void 0 : _thumbnails.length) > 0) && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("video", {
    className: "sendbird-quote-message__replied-message__thumbnail-message__video"
  }, /*#__PURE__*/React__default["default"].createElement("source", {
    src: parentMessageUrl,
    type: parentMessageType
  })), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-quote-message__replied-message__thumbnail-message__cover"
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-quote-message__replied-message__thumbnail-message__cover__icon"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    type: ui_Icon.IconTypes.PLAY,
    fillColor: ui_Icon.IconColors.GRAY,
    width: "14px",
    height: "14px"
  })))), isThumbnailLoaded && index.isGif(parentMessageType) && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-quote-message__replied-message__thumbnail-message__cover"
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-quote-message__replied-message__thumbnail-message__cover__icon"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    type: ui_Icon.IconTypes.GIF,
    fillColor: ui_Icon.IconColors.GRAY,
    width: "14px",
    height: "14px"
  })))), index.getUIKitMessageType(parentMessage) === index.UIKitMessageTypes.FILE && parentMessageUrl && !isUnavailable && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-quote-message__replied-message__file-message"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    className: "sendbird-quote-message__replied-message__file-message__type-icon",
    type: {
      [uikitFileTypes.IMAGE]: ui_Icon.IconTypes.PHOTO,
      [uikitFileTypes.VIDEO]: ui_Icon.IconTypes.PLAY,
      [uikitFileTypes.AUDIO]: ui_Icon.IconTypes.FILE_AUDIO,
      [uikitFileTypes.GIF]: ui_Icon.IconTypes.GIF,
      [uikitFileTypes.OTHERS]: ui_Icon.IconTypes.FILE_DOCUMENT
    }[index.getUIKitFileType(parentMessageType)],
    fillColor: ui_Icon.IconColors.ON_BACKGROUND_3,
    width: "16px",
    height: "16px"
  }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-quote-message__replied-message__file-message__file-name",
    type: ui_Label.LabelTypography.BODY_2,
    color: ui_Label.LabelColors.ONBACKGROUND_3
  }, index.truncateString(splitFileName[splitFileName.length - 1])))));
}

module.exports = QuoteMessage;
//# sourceMappingURL=QuoteMessage.js.map
