import React__default from 'react';
import Avatar from './Avatar.js';
import Icon, { IconTypes, IconColors } from './Icon.js';
import { L as Label, a as LabelTypography, b as LabelColors } from '../index-4105bc4d.js';
import { u as useLocalization } from '../LocalizationContext-426f3d58.js';
import { f as format } from '../index-e7f4cbdf.js';
import { i as isToday, a as isYesterday, b as isThisYear } from '../index-65ed45e9.js';
import { d as isVoiceMessage } from '../index-f83f0aac.js';
import './ImageRenderer.js';
import '../uuid-2e8efc75.js';
import 'prop-types';
import '../stringSet-a62108b2.js';
import '../index-90420b99.js';
import '../index-e40d8b24.js';
import '../_rollupPluginBabelHelpers-a69fd1ce.js';
import '../utils/message/getOutgoingMessageState.js';

function getCreatedAt(_ref) {
  let {
    createdAt,
    locale,
    stringSet
  } = _ref;
  const optionalParam = locale ? {
    locale
  } : null;
  if (!createdAt) {
    return '';
  }
  if (isToday(createdAt)) {
    return format(createdAt, 'p', optionalParam);
  }
  if (isYesterday(createdAt)) {
    return (stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_STATUS__YESTERDAY) || 'Yesterday';
  }
  if (isThisYear(createdAt)) {
    return format(createdAt, 'MMM d', optionalParam);
  }
  return 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 IconTypes.PHOTO;
  } else if (/mp4$/i.test(fileExtension) || isVoiceMessage(message)) {
    return IconTypes.PLAY;
  } else if (/mp3/i.test(fileExtension)) {
    return IconTypes.FILE_AUDIO;
  } else if (/gif/i.test(fileExtension)) {
    return IconTypes.GIF;
  } else {
    return 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
  } = useLocalization();
  const isVoiceMsg = isVoiceMessage(message);
  const prettyFilename = isVoiceMsg ? stringSet.VOICE_MESSAGE : name || url;
  return /*#__PURE__*/React__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.createElement("div", {
    className: "sendbird-message-search-file-item__left"
  }, /*#__PURE__*/React__default.createElement(Avatar, {
    className: "sendbird-message-search-file-item__left__sender-avatar",
    src: profileUrl,
    alt: "profile image",
    width: "56px",
    height: "56px"
  })), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-message-search-file-item__right"
  }, /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-message-search-file-item__right__sender-name",
    type: LabelTypography.SUBTITLE_2,
    color: LabelColors.ONBACKGROUND_1
  }, nickname || stringSet.NO_NAME), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-message-search-file-item__right__content"
  }, !isVoiceMsg && /*#__PURE__*/React__default.createElement("div", {
    className: 'sendbird-message-search-file-item__right__content__type-icon'
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: getIconOfFileType(message),
    fillColor: IconColors.PRIMARY,
    width: "18px",
    height: "18px"
  })), /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-message-search-file-item__right__content__url",
    type: LabelTypography.BODY_2,
    color: LabelColors.ONBACKGROUND_1
  }, prettyFilename))), /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-message-search-file-item__message-created-at",
    type: LabelTypography.CAPTION_3,
    color: LabelColors.ONBACKGROUND_2
  }, getCreatedAt({
    createdAt,
    locale: dateLocale,
    stringSet
  })), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-message-search-file-item__right-footer"
  }));
}

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