'use strict';

var React = require('react');
var index$1 = require('../index-3fc4f7d7.js');
var index = require('../index-0e24aca4.js');
var ui_Avatar = require('./Avatar.js');
var ui_Label = require('../index-35633fb6.js');
var LocalizationContext = require('../LocalizationContext-8cc9717d.js');
require('../index-d749c4c2.js');
require('../index-bf8f9551.js');
require('./ImageRenderer.js');
require('./Icon.js');
require('prop-types');
require('../uuid-1eceb0c8.js');
require('../stringSet-ce782136.js');

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

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

// getCreatedAt
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 MessageSearchItem(_ref) {
  let {
    className,
    message,
    selected,
    onClick
  } = _ref;
  const {
    createdAt
  } = message;
  const messageText = message.message;
  const sender = message.sender || message._sender;
  const {
    profileUrl,
    nickname
  } = sender;
  const {
    stringSet,
    dateLocale
  } = LocalizationContext.useLocalization();
  return /*#__PURE__*/React__default["default"].createElement("div", {
    className: [...(Array.isArray(className) ? className : [className]), 'sendbird-message-search-item', selected ? 'sendbird-message-search-item--selected' : ''].join(' '),
    onClick: e => {
      e.stopPropagation();
      onClick(message);
    }
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message-search-item__left"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Avatar["default"], {
    className: "sendbird-message-search-item__left__sender-avatar",
    src: profileUrl,
    alt: "profile image",
    width: "56px",
    height: "56px"
  })), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message-search-item__right"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-message-search-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(ui_Label.Label, {
    className: "sendbird-message-search-item__right__message-text",
    type: ui_Label.LabelTypography.BODY_2,
    color: ui_Label.LabelColors.ONBACKGROUND_3
  }, messageText), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-message-search-item__right__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-item__right-footer"
  }));
}

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