import React__default, { useContext, useState } from 'react';
import Icon, { IconTypes, IconColors } from './Icon.js';
import { L as Label, a as LabelTypography, b as LabelColors } from '../index-4105bc4d.js';
import ImageRenderer from './ImageRenderer.js';
import { a as LocalizationContext } from '../LocalizationContext-426f3d58.js';
import { M as getUIKitFileTypes, h as getClassName, q as isUserMessage, d as isVoiceMessage, m as isThumbnailMessage, y as isVideo, N as isGif, r as getUIKitMessageType, U as UIKitMessageTypes, L as getUIKitFileType, t as truncateString } from '../index-f83f0aac.js';
import 'prop-types';
import '../stringSet-a62108b2.js';
import '../index-90420b99.js';
import '../_rollupPluginBabelHelpers-a69fd1ce.js';
import '../utils/message/getOutgoingMessageState.js';

function QuoteMessage(_ref) {
  var _message$sender, _message$sender2, _message, _thumbnails;
  let {
    message,
    userId = '',
    isByMe = false,
    className = '',
    isUnavailable = false,
    onClick
  } = _ref;
  const {
    stringSet
  } = useContext(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] = useState(false);
  const uikitFileTypes = getUIKitFileTypes();
  const splitFileName = parentMessage !== null && parentMessage !== void 0 && parentMessage.name ? parentMessage.name.split('/') : parentMessageUrl.split('/');
  return /*#__PURE__*/React__default.createElement("div", {
    className: 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.createElement("div", {
    className: "sendbird-quote-message__replied-to"
  }, /*#__PURE__*/React__default.createElement(Icon, {
    className: "sendbird-quote-message__replied-to__icon",
    type: IconTypes.REPLY,
    fillColor: IconColors.ON_BACKGROUND_3,
    width: "12px",
    height: "12px"
  }), /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-quote-message__replied-to__text",
    type: LabelTypography.CAPTION_2,
    color: LabelColors.ONBACKGROUND_3
  }, /*#__PURE__*/React__default.createElement("span", {
    className: "sendbird-quote-message__replied-to__text__nickname"
  }, currentMessageSenderNickname), /*#__PURE__*/React__default.createElement("span", {
    className: "sendbird-quote-message__replied-to__text__text"
  }, stringSet.QUOTED_MESSAGE__REPLIED_TO), /*#__PURE__*/React__default.createElement("span", {
    className: "sendbird-quote-message__replied-to__text__nickname"
  }, parentMessageSenderNickname))), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-quote-message__replied-message"
  }, isUnavailable && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-quote-message__replied-message__text-message"
  }, /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-quote-message__replied-message__text-message__word",
    type: LabelTypography.BODY_2,
    color: LabelColors.ONBACKGROUND_1
  }, stringSet.QUOTED_MESSAGE__UNAVAILABLE)), 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.createElement("div", {
    className: "sendbird-quote-message__replied-message__text-message"
  }, /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-quote-message__replied-message__text-message__word",
    type: LabelTypography.BODY_2,
    color: LabelColors.ONBACKGROUND_1
  }, parentMessage === null || parentMessage === void 0 ? void 0 : parentMessage.message)), isVoiceMessage(parentMessage) && parentMessageUrl && !isUnavailable && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-quote-message__replied-message__text-message"
  }, /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-quote-message__replied-message__text-message__word",
    type: LabelTypography.BODY_2,
    color: LabelColors.ONBACKGROUND_1
  }, stringSet.VOICE_MESSAGE)), isThumbnailMessage(parentMessage) && parentMessageUrl && !isUnavailable && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-quote-message__replied-message__thumbnail-message"
  }, /*#__PURE__*/React__default.createElement(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.createElement("div", {
      className: "sendbird-quote-message__replied-message__thumbnail-message__placeholder"
    }, /*#__PURE__*/React__default.createElement("div", {
      className: "sendbird-quote-message__replied-message__thumbnail-message__placeholder__icon"
    }, /*#__PURE__*/React__default.createElement(Icon, {
      type: isVideo(parentMessageType) ? IconTypes.PLAY : IconTypes.PHOTO,
      fillColor: IconColors.ON_BACKGROUND_2,
      width: "22px",
      height: "22px"
    })))
  }), isVideo(parentMessageType) && !((parentMessage === null || parentMessage === void 0 ? void 0 : (_thumbnails = parentMessage.thumbnails) === null || _thumbnails === void 0 ? void 0 : _thumbnails.length) > 0) && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("video", {
    className: "sendbird-quote-message__replied-message__thumbnail-message__video"
  }, /*#__PURE__*/React__default.createElement("source", {
    src: parentMessageUrl,
    type: parentMessageType
  })), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-quote-message__replied-message__thumbnail-message__cover"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-quote-message__replied-message__thumbnail-message__cover__icon"
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: IconTypes.PLAY,
    fillColor: IconColors.GRAY,
    width: "14px",
    height: "14px"
  })))), isThumbnailLoaded && isGif(parentMessageType) && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-quote-message__replied-message__thumbnail-message__cover"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-quote-message__replied-message__thumbnail-message__cover__icon"
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: IconTypes.GIF,
    fillColor: IconColors.GRAY,
    width: "14px",
    height: "14px"
  })))), getUIKitMessageType(parentMessage) === UIKitMessageTypes.FILE && parentMessageUrl && !isUnavailable && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-quote-message__replied-message__file-message"
  }, /*#__PURE__*/React__default.createElement(Icon, {
    className: "sendbird-quote-message__replied-message__file-message__type-icon",
    type: {
      [uikitFileTypes.IMAGE]: IconTypes.PHOTO,
      [uikitFileTypes.VIDEO]: IconTypes.PLAY,
      [uikitFileTypes.AUDIO]: IconTypes.FILE_AUDIO,
      [uikitFileTypes.GIF]: IconTypes.GIF,
      [uikitFileTypes.OTHERS]: IconTypes.FILE_DOCUMENT
    }[getUIKitFileType(parentMessageType)],
    fillColor: IconColors.ON_BACKGROUND_3,
    width: "16px",
    height: "16px"
  }), /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-quote-message__replied-message__file-message__file-name",
    type: LabelTypography.BODY_2,
    color: LabelColors.ONBACKGROUND_3
  }, truncateString(splitFileName[splitFileName.length - 1])))));
}

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