import { b as _extends, _ as _objectSpread2 } from '../../_rollupPluginBabelHelpers-4f8ebde4.js';
import React__default, { useState } from 'react';
import ChannelAvatar from '../../ui/ChannelAvatar.js';
import Badge from '../../ui/Badge.js';
import Icon, { IconTypes, IconColors } from '../../ui/Icon.js';
import { L as Label, a as LabelTypography, b as LabelColors } from '../../index-4372fcec.js';
import { g as getChannelTitle, a as getTotalMembers, M as MessageStatus, b as getLastMessageCreatedAt, c as getLastMessage, d as getChannelUnreadMessageCount } from '../../index-1d741554.js';
import useSendbirdStateContext from '../../useSendbirdStateContext.js';
import { u as useLocalization } from '../../LocalizationContext-b2390bf8.js';
import MentionUserLabel from '../../ui/MentionUserLabel.js';
import Modal from '../../ui/Modal.js';
import TextButton from '../../ui/TextButton.js';
import { u as useChannelListContext } from '../../ChannelListProvider-0605a997.js';
import { TypingIndicatorText } from '../../Channel/components/TypingIndicator.js';
import { d as isVoiceMessage } from '../../index-eefb44ba.js';
import { u as useMediaQueryContext } from '../../MediaQueryContext-b4904a2e.js';
import { u as useLongPress } from '../../useLongPress-cb2d23be.js';
import '../../ui/Avatar.js';
import '../../ui/ImageRenderer.js';
import '../../uuid-a79b5ba8.js';
import '../../utils-9e1bd161.js';
import 'prop-types';
import '../../stringSet-eefbc798.js';
import '../../index-2dc53ac2.js';
import '../../index-67135027.js';
import '../../ui/Loader.js';
import '../../utils/message/getOutgoingMessageState.js';
import '../../index-0d1114ee.js';
import '../../index-39306dfb.js';
import '../../withSendbird.js';
import '../../consts-8ce876a0.js';
import 'react-dom';
import '../../index-896545a0.js';
import '../../ui/Button.js';
import '../../ui/IconButton.js';
import '../../color-9519a526.js';
import '@sendbird/chat/groupChannel';
import '../../topics-f3629ea0.js';
import '../../utils-b53fe532.js';
import '../../UserProfileContext-d5787c95.js';
import '../../ChannelProvider-498954bf.js';
import '../../const-97fac210.js';
import '../../compareIds-7800035f.js';
import '@sendbird/chat/message';
import '../../consts-33537265.js';
import '../../resolvedReplyType-e00d5fd9.js';

const ChannelPreview = _ref => {
  var _sbState$stores, _sbState$stores$userS, _sbState$stores$userS2, _sbState$config, _sbState$config2, _channel$lastMessage, _channel$lastMessage2, _channel$lastMessage3, _channel$lastMessage4;
  let {
    channel,
    isActive = false,
    isTyping = false,
    renderChannelAction,
    onLeaveChannel,
    onClick,
    tabIndex
  } = _ref;
  const sbState = useSendbirdStateContext();
  const {
    isTypingIndicatorEnabled = false,
    isMessageReceiptStatusEnabled = false
  } = useChannelListContext();
  const {
    dateLocale,
    stringSet
  } = useLocalization();
  const {
    isMobile
  } = useMediaQueryContext();
  const [showMobileLeave, setShowMobileLeave] = useState(false);
  const userId = sbState === null || sbState === void 0 ? void 0 : (_sbState$stores = sbState.stores) === null || _sbState$stores === void 0 ? void 0 : (_sbState$stores$userS = _sbState$stores.userStore) === null || _sbState$stores$userS === void 0 ? void 0 : (_sbState$stores$userS2 = _sbState$stores$userS.user) === null || _sbState$stores$userS2 === void 0 ? void 0 : _sbState$stores$userS2.userId;
  const theme = sbState === null || sbState === void 0 ? void 0 : (_sbState$config = sbState.config) === null || _sbState$config === void 0 ? void 0 : _sbState$config.theme;
  const isMentionEnabled = sbState === null || sbState === void 0 ? void 0 : (_sbState$config2 = sbState.config) === null || _sbState$config2 === void 0 ? void 0 : _sbState$config2.isMentionEnabled;
  const isFrozen = (channel === null || channel === void 0 ? void 0 : channel.isFrozen) || false;
  const isBroadcast = (channel === null || channel === void 0 ? void 0 : channel.isBroadcast) || false;
  const isChannelTyping = isTypingIndicatorEnabled && isTyping;
  const isMessageStatusEnabled = isMessageReceiptStatusEnabled && ((channel === null || channel === void 0 ? void 0 : (_channel$lastMessage = channel.lastMessage) === null || _channel$lastMessage === void 0 ? void 0 : _channel$lastMessage.messageType) === 'user' || (channel === null || channel === void 0 ? void 0 : (_channel$lastMessage2 = channel.lastMessage) === null || _channel$lastMessage2 === void 0 ? void 0 : _channel$lastMessage2.messageType) === 'file') && (channel === null || channel === void 0 ? void 0 : (_channel$lastMessage3 = channel.lastMessage) === null || _channel$lastMessage3 === void 0 ? void 0 : (_channel$lastMessage4 = _channel$lastMessage3.sender) === null || _channel$lastMessage4 === void 0 ? void 0 : _channel$lastMessage4.userId) === userId;
  const onLongPress = useLongPress({
    onLongPress: () => {
      if (isMobile) {
        setShowMobileLeave(true);
      }
    },
    onClick
  }, {
    delay: 1000
  });
  const channelName = getChannelTitle(channel, userId, stringSet);
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", _extends({
    className: ['sendbird-channel-preview', isActive ? 'sendbird-channel-preview--active' : ''].join(' '),
    role: "link",
    tabIndex: tabIndex
  }, isMobile ? _objectSpread2({}, onLongPress) : {
    onClick
  }), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-preview__avatar"
  }, /*#__PURE__*/React__default.createElement(ChannelAvatar, {
    channel: channel,
    userId: userId,
    theme: theme
  })), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-preview__content"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-preview__content__upper"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-preview__content__upper__header"
  }, isBroadcast && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-preview__content__upper__header__broadcast-icon"
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: IconTypes.BROADCAST,
    fillColor: IconColors.SECONDARY,
    height: "16px",
    width: "16px"
  })), /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-channel-preview__content__upper__header__channel-name",
    type: LabelTypography.SUBTITLE_2,
    color: LabelColors.ONBACKGROUND_1
  }, channelName), /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-channel-preview__content__upper__header__total-members",
    type: LabelTypography.CAPTION_2,
    color: LabelColors.ONBACKGROUND_2
  }, getTotalMembers(channel)), isFrozen && /*#__PURE__*/React__default.createElement("div", {
    title: "Frozen",
    className: "sendbird-channel-preview__content__upper__header__frozen-icon"
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: IconTypes.FREEZE,
    fillColor: IconColors.PRIMARY,
    height: 12,
    width: 12
  }))), !(channel !== null && channel !== void 0 && channel.isEphemeral) && isMessageStatusEnabled && /*#__PURE__*/React__default.createElement(MessageStatus, {
    className: "sendbird-channel-preview__content__upper__last-message-at",
    channel: channel,
    message: channel === null || channel === void 0 ? void 0 : channel.lastMessage,
    isDateSeparatorConsidered: false
  }), !(channel !== null && channel !== void 0 && channel.isEphemeral) && !isMessageStatusEnabled && /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-channel-preview__content__upper__last-message-at",
    type: LabelTypography.CAPTION_3,
    color: LabelColors.ONBACKGROUND_2
  }, getLastMessageCreatedAt({
    channel,
    locale: dateLocale,
    stringSet
  }))), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-preview__content__lower"
  }, /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-channel-preview__content__lower__last-message",
    type: LabelTypography.BODY_2,
    color: LabelColors.ONBACKGROUND_3
  }, isChannelTyping && /*#__PURE__*/React__default.createElement(TypingIndicatorText, {
    members: channel === null || channel === void 0 ? void 0 : channel.getTypingUsers()
  }), !isChannelTyping && !isVoiceMessage(channel === null || channel === void 0 ? void 0 : channel.lastMessage) && getLastMessage(channel), !isChannelTyping && isVoiceMessage(channel === null || channel === void 0 ? void 0 : channel.lastMessage) && stringSet.VOICE_MESSAGE), !(channel !== null && channel !== void 0 && channel.isEphemeral) && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-preview__content__lower__unread-message-count"
  }, isMentionEnabled && (channel === null || channel === void 0 ? void 0 : channel.unreadMentionCount) > 0 ? /*#__PURE__*/React__default.createElement(MentionUserLabel, {
    className: "sendbird-channel-preview__content__lower__unread-message-count__mention",
    color: "purple"
  }, '@') : null, getChannelUnreadMessageCount(channel) // return number
  ? /*#__PURE__*/React__default.createElement(Badge, {
    count: getChannelUnreadMessageCount(channel)
  }) : null))), !isMobile && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-preview__action"
  }, renderChannelAction({
    channel
  }))), showMobileLeave && isMobile && /*#__PURE__*/React__default.createElement(Modal, {
    className: "sendbird-channel-preview__leave--mobile",
    titleText: channelName,
    hideFooter: true,
    isCloseOnClickOutside: true,
    onCancel: () => setShowMobileLeave(false)
  }, /*#__PURE__*/React__default.createElement(TextButton, {
    onClick: () => {
      onLeaveChannel();
      setShowMobileLeave(false);
    },
    className: "sendbird-channel-preview__leave-label--mobile"
  }, /*#__PURE__*/React__default.createElement(Label, {
    type: LabelTypography.SUBTITLE_1,
    color: LabelColors.ONBACKGROUND_1
  }, stringSet.CHANNEL_PREVIEW_MOBILE_LEAVE))));
};

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