var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.MessageStatus = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
var _ChannelContext = require("../../../contexts/channelContext/ChannelContext");
var _MessageContext = require("../../../contexts/messageContext/MessageContext");
var _ThemeContext = require("../../../contexts/themeContext/ThemeContext");
var _Check = require("../../../icons/Check");
var _CheckAll = require("../../../icons/CheckAll");
var _Time = require("../../../icons/Time");
var _utils = require("../../../utils/utils");
var _jsxRuntime = require("react/jsx-runtime");
var _this = this,
  _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/components/Message/MessageSimple/MessageStatus.tsx";
var MessageStatusWithContext = function MessageStatusWithContext(props) {
  var _useChannelContext = (0, _ChannelContext.useChannelContext)(),
    channel = _useChannelContext.channel;
  var message = props.message,
    readBy = props.readBy,
    threadList = props.threadList;
  var _useTheme = (0, _ThemeContext.useTheme)(),
    _useTheme$theme = _useTheme.theme,
    _useTheme$theme$color = _useTheme$theme.colors,
    accent_blue = _useTheme$theme$color.accent_blue,
    grey_dark = _useTheme$theme$color.grey_dark,
    _useTheme$theme$messa = _useTheme$theme.messageSimple.status,
    checkAllIcon = _useTheme$theme$messa.checkAllIcon,
    checkIcon = _useTheme$theme$messa.checkIcon,
    readByCount = _useTheme$theme$messa.readByCount,
    statusContainer = _useTheme$theme$messa.statusContainer,
    timeIcon = _useTheme$theme$messa.timeIcon;
  if (message.status === _utils.MessageStatusTypes.SENDING) {
    return (0, _jsxRuntime.jsx)(_reactNative.View, {
      style: [styles.statusContainer, statusContainer],
      testID: "sending-container",
      children: (0, _jsxRuntime.jsx)(_Time.Time, Object.assign({}, timeIcon))
    });
  }
  if (threadList || message.status === _utils.MessageStatusTypes.FAILED) {
    return null;
  }
  if (readBy) {
    var members = channel == null ? void 0 : channel.state.members;
    var otherMembers = Object.values(members).filter(function (member) {
      var _message$user;
      return member.user_id !== ((_message$user = message.user) == null ? void 0 : _message$user.id);
    });
    var hasOtherMembersGreaterThanOne = otherMembers.length > 1;
    var hasReadByGreaterThanOne = typeof readBy === 'number' && readBy > 1;
    var shouldDisplayReadByCount = hasOtherMembersGreaterThanOne && hasReadByGreaterThanOne;
    var countOfReadBy = typeof readBy === 'number' && hasOtherMembersGreaterThanOne ? readBy - 1 : 0;
    var showDoubleCheck = hasReadByGreaterThanOne || readBy === true;
    return (0, _jsxRuntime.jsxs)(_reactNative.View, {
      style: [styles.statusContainer, statusContainer],
      children: [shouldDisplayReadByCount ? (0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: [styles.readByCount, {
          color: accent_blue
        }, readByCount],
        testID: "read-by-container",
        children: countOfReadBy
      }) : null, message.type !== 'error' ? showDoubleCheck ? (0, _jsxRuntime.jsx)(_CheckAll.CheckAll, Object.assign({
        pathFill: accent_blue
      }, checkAllIcon)) : (0, _jsxRuntime.jsx)(_Check.Check, Object.assign({
        pathFill: grey_dark
      }, checkIcon)) : null]
    });
  }
  if (message.status === _utils.MessageStatusTypes.RECEIVED && message.type !== 'ephemeral') {
    return (0, _jsxRuntime.jsx)(_reactNative.View, {
      style: [styles.statusContainer, statusContainer],
      testID: "delivered-container",
      children: (0, _jsxRuntime.jsx)(_Check.Check, Object.assign({
        pathFill: grey_dark
      }, checkIcon))
    });
  }
  return null;
};
var areEqual = function areEqual(prevProps, nextProps) {
  var prevMessage = prevProps.message,
    prevReadBy = prevProps.readBy,
    prevThreadList = prevProps.threadList;
  var nextMessage = nextProps.message,
    nextReadBy = nextProps.readBy,
    nextThreadList = nextProps.threadList;
  var threadListEqual = prevThreadList === nextThreadList;
  if (!threadListEqual) {
    return false;
  }
  var readByEqual = prevReadBy === nextReadBy;
  if (!readByEqual) {
    return false;
  }
  var messageEqual = prevMessage.status === nextMessage.status && prevMessage.type === nextMessage.type;
  if (!messageEqual) {
    return false;
  }
  return true;
};
var MemoizedMessageStatus = _react["default"].memo(MessageStatusWithContext, areEqual);
var MessageStatus = exports.MessageStatus = function MessageStatus(props) {
  var _useMessageContext = (0, _MessageContext.useMessageContext)(),
    message = _useMessageContext.message,
    readBy = _useMessageContext.readBy,
    threadList = _useMessageContext.threadList;
  return (0, _jsxRuntime.jsx)(MemoizedMessageStatus, Object.assign({
    message: message,
    readBy: readBy,
    threadList: threadList
  }, props));
};
MessageStatus.displayName = 'MessageStatus{messageSimple{status}}';
var styles = _reactNative.StyleSheet.create({
  readByCount: {
    fontSize: 11,
    fontWeight: '700',
    paddingRight: 3
  },
  statusContainer: {
    alignItems: 'flex-end',
    flexDirection: 'row',
    justifyContent: 'center',
    paddingRight: 3
  }
});
//# sourceMappingURL=MessageStatus.js.map