'use strict';

var React = require('react');
var ui_Avatar = require('./Avatar.js');
var ui_Icon = require('./Icon.js');
var ui_Label = require('../index-bff918b2.js');
var LocalizationContext = require('../LocalizationContext-6adf6aa8.js');
var index$1 = require('../index-358554d2.js');
var index = require('../index-e43a902a.js');
var index$2 = require('../index-86e680cb.js');
require('./ImageRenderer.js');
require('../uuid-f1d9be11.js');
require('prop-types');
require('../stringSet-5157206d.js');
require('../index-6a7f94de.js');
require('../index-66630f40.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 getCreatedAt(_ref) {
  let {
    createdAt,
    locale,
    stringSet
  } = _ref;
  const optionalParam = locale ? {
    locale
  } : null;
  if (!createdAt) {
    return '';
  }
  if (index.isToday(createdAt)) {
    return index$1.format(createdAt, 'p', optionalParam);
  }
  if (index.isYesterday(createdAt)) {
    return (stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_STATUS__YESTERDAY) || 'Yesterday';
  }
  if (index.isThisYear(createdAt)) {
    return index$1.format(createdAt, 'MMM d', optionalParam);
  }
  return index$1.format(createdAt, 'yyyy/M/d', optionalParam);
}
function getIconOfFileType(message) {
  const {
    url
  } = message;
  const fileMessageUrl = url;
  const fileExtension = fileMessageUrl.match(/\.([^.]*?)(?=\?|#|$)/)[1];
  if (/(jpg|jpeg|png)$/i.test(fileExtension)) {
    return ui_Icon.IconTypes.PHOTO;
  } else if (/mp4$/i.test(fileExtension) || index$2.isVoiceMessage(message)) {
    return ui_Icon.IconTypes.PLAY;
  } else if (/mp3/i.test(fileExtension)) {
    return ui_Icon.IconTypes.FILE_AUDIO;
  } else if (/gif/i.test(fileExtension)) {
    return ui_Icon.IconTypes.GIF;
  } else {
    return ui_Icon.IconTypes.FILE_DOCUMENT;
  }
}

function MessageSearchFileItem(props) {
  const {
    className,
    message,
    selected,
    onClick
  } = props;
  const {
    createdAt,
    url,
    name
  } = message;
  // @ts-ignore
  const sender = message.sender || message._sender;
  const {
    profileUrl,
    nickname
  } = sender;
  const {
    stringSet,
    dateLocale
  } = LocalizationContext.useLocalization();
  const isVoiceMsg = index$2.isVoiceMessage(message);
  const prettyFilename = isVoiceMsg ? stringSet.VOICE_MESSAGE : name || url;
  return /*#__PURE__*/React__default["default"].createElement("div", {
    className: [...(Array.isArray(className) ? className : [className]), 'sendbird-message-search-file-item', selected ? 'sendbird-message-search-file-item--selected' : ''].join(' '),
    onClick: e => {
      e.stopPropagation();
      onClick(message);
    }
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message-search-file-item__left"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Avatar["default"], {
    className: "sendbird-message-search-file-item__left__sender-avatar",
    src: profileUrl,
    alt: "profile image",
    width: "56px",
    height: "56px"
  })), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message-search-file-item__right"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-message-search-file-item__right__sender-name",
    type: ui_Label.LabelTypography.SUBTITLE_2,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, nickname || stringSet.NO_NAME), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message-search-file-item__right__content"
  }, !isVoiceMsg && /*#__PURE__*/React__default["default"].createElement("div", {
    className: 'sendbird-message-search-file-item__right__content__type-icon'
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    type: getIconOfFileType(message),
    fillColor: ui_Icon.IconColors.PRIMARY,
    width: "18px",
    height: "18px"
  })), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-message-search-file-item__right__content__url",
    type: ui_Label.LabelTypography.BODY_2,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, prettyFilename))), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-message-search-file-item__message-created-at",
    type: ui_Label.LabelTypography.CAPTION_3,
    color: ui_Label.LabelColors.ONBACKGROUND_2
  }, getCreatedAt({
    createdAt,
    locale: dateLocale,
    stringSet
  })), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message-search-file-item__right-footer"
  }));
}

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