"use strict";Object.defineProperty(exports, "__esModule", {value: true});

var _chunkKNTAARQFjs = require('./chunk-KNTAARQF.js');


var _chunk5YP3QLWRjs = require('./chunk-5YP3QLWR.js');


var _chunkK4K3QV2Qjs = require('./chunk-K4K3QV2Q.js');


var _chunkJM3OL3A2js = require('./chunk-JM3OL3A2.js');


var _chunkWNLWBCMAjs = require('./chunk-WNLWBCMA.js');


var _chunkVPKGCVB7js = require('./chunk-VPKGCVB7.js');


var _chunk3UWDRSIKjs = require('./chunk-3UWDRSIK.js');


var _chunkUYBEH4KAjs = require('./chunk-UYBEH4KA.js');


var _chunkIFVB5H42js = require('./chunk-IFVB5H42.js');

// tmp-babel/messages/web/AllChatRoomsList/ChatRoomItem/index.js
var _react = require('react');
var _authentication = require('@baseapp-frontend/authentication');
var _avatars = require('@baseapp-frontend/design-system/components/web/avatars');
var _icons = require('@baseapp-frontend/design-system/components/web/icons');
var _typographies = require('@baseapp-frontend/design-system/components/web/typographies');
var _material = require('@mui/material');
var _reactrelay = require('react-relay');
var _jsxruntime = require('react/jsx-runtime');
function _typeof(o) {
  "@babel/helpers - typeof";
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
    return typeof o2;
  } : function(o2) {
    return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
  }, _typeof(o);
}
function ownKeys(e, r) {
  var t = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var o = Object.getOwnPropertySymbols(e);
    r && (o = o.filter(function(r2) {
      return Object.getOwnPropertyDescriptor(e, r2).enumerable;
    })), t.push.apply(t, o);
  }
  return t;
}
function _objectSpread(e) {
  for (var r = 1; r < arguments.length; r++) {
    var t = null != arguments[r] ? arguments[r] : {};
    r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
      _defineProperty(e, r2, t[r2]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
      Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
    });
  }
  return e;
}
function _defineProperty(e, r, t) {
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey(t) {
  var i = _toPrimitive(t, "string");
  return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
  if ("object" != _typeof(t) || !t) return t;
  var e = t[Symbol.toPrimitive];
  if (void 0 !== e) {
    var i = e.call(t, r || "default");
    if ("object" != _typeof(i)) return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return ("string" === r ? String : Number)(t);
}
function _slicedToArray(r, e) {
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _nonIterableRest() {
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray(r, a) {
  if (r) {
    if ("string" == typeof r) return _arrayLikeToArray(r, a);
    var t = {}.toString.call(r).slice(8, -1);
    return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  }
}
function _arrayLikeToArray(r, a) {
  (null == a || a > r.length) && (a = r.length);
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  return n;
}
function _iterableToArrayLimit(r, l) {
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  if (null != t) {
    var e, n, i, u, a = [], f = true, o = false;
    try {
      if (i = (t = t.call(r)).next, 0 === l) {
        if (Object(t) !== t) return;
        f = false;
      } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
    } catch (r2) {
      o = true, n = r2;
    } finally {
      try {
        if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
      } finally {
        if (o) throw n;
      }
    }
    return a;
  }
}
function _arrayWithHoles(r) {
  if (Array.isArray(r)) return r;
}
var ChatRoomItem = function ChatRoomItem2(_ref) {
  var _lastMessageFragment$, _unreadMessagesCountF, _unreadMessagesCountF2, _unreadMessagesCountF3;
  var roomRef = _ref.roomRef, _ref$isCardSelected = _ref.isCardSelected, isCardSelected = _ref$isCardSelected === void 0 ? false : _ref$isCardSelected, handleClick = _ref.handleClick, _ref$Badge = _ref.Badge, Badge = _ref$Badge === void 0 ? _material.Badge : _ref$Badge, _ref$BadgeProps = _ref.BadgeProps, BadgeProps = _ref$BadgeProps === void 0 ? {} : _ref$BadgeProps, _ref$isInArchivedTab = _ref.isInArchivedTab, isInArchivedTab = _ref$isInArchivedTab === void 0 ? false : _ref$isInArchivedTab;
  var lastMessageFragment = _reactrelay.useFragment.call(void 0, _chunk3UWDRSIKjs.LastMessageFragment, roomRef);
  var headerFragment = _reactrelay.useFragment.call(void 0, _chunkJM3OL3A2js.TitleFragment, roomRef);
  var unreadMessagesCountFragment = _reactrelay.useFragment.call(void 0, _chunkWNLWBCMAjs.UnreadMessagesCountFragment, roomRef);
  var _useUnreadChatMutatio = _chunkK4K3QV2Qjs.useUnreadChatMutation.call(void 0, ), _useUnreadChatMutatio2 = _slicedToArray(_useUnreadChatMutatio, 1), commitMutation = _useUnreadChatMutatio2[0];
  var handleCardClick = function handleCardClick2(event) {
    event.stopPropagation();
    if (handleClick) handleClick();
  };
  var chatCardRef = _react.useRef.call(void 0, null);
  var _useCurrentProfile = _authentication.useCurrentProfile.call(void 0, ), currentProfile = _useCurrentProfile.currentProfile;
  var _useNameAndAvatar = _chunkUYBEH4KAjs.useNameAndAvatar.call(void 0, headerFragment), title = _useNameAndAvatar.title, avatar = _useNameAndAvatar.avatar;
  var lastMessageTime = lastMessageFragment.lastMessageTime;
  var lastMessage = (_lastMessageFragment$ = lastMessageFragment.lastMessage) === null || _lastMessageFragment$ === void 0 ? void 0 : _lastMessageFragment$.content;
  var hasUnreadMessages = ((_unreadMessagesCountF = unreadMessagesCountFragment.unreadMessages) === null || _unreadMessagesCountF === void 0 ? void 0 : _unreadMessagesCountF.markedUnread) || !!((_unreadMessagesCountF2 = unreadMessagesCountFragment.unreadMessages) !== null && _unreadMessagesCountF2 !== void 0 && _unreadMessagesCountF2.count);
  var unreadChat = _react.useCallback.call(void 0, function() {
    commitMutation({
      variables: {
        input: {
          roomId: roomRef.id,
          profileId: currentProfile === null || currentProfile === void 0 ? void 0 : currentProfile.id
        }
      }
    });
  }, [roomRef.id, currentProfile]);
  var _useArchiveChatRoomMu = _chunkVPKGCVB7js.useArchiveChatRoomMutation.call(void 0, ), _useArchiveChatRoomMu2 = _slicedToArray(_useArchiveChatRoomMu, 2), commit = _useArchiveChatRoomMu2[0], isMutationInFlight = _useArchiveChatRoomMu2[1];
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkIFVB5H42js.ActionsOverlay_default, {
    title: "Chat",
    offsetTop: -12,
    actions: [{
      disabled: isMutationInFlight,
      icon: !isInArchivedTab ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _icons.ArchiveIcon, {}) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _icons.UnarchiveIcon, {}),
      label: !isInArchivedTab ? "Archive Chat" : "Unarchive Chat",
      onClick: function onClick() {
        if (currentProfile !== null && currentProfile !== void 0 && currentProfile.id) {
          commit({
            variables: {
              input: {
                roomId: roomRef.id,
                profileId: currentProfile.id,
                archive: !isInArchivedTab
              }
            }
          });
        }
      },
      hasPermission: true
    }, {
      disabled: hasUnreadMessages,
      icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _icons.UnreadIcon, {}),
      label: "Mark as Unread",
      onClick: unreadChat,
      hasPermission: true,
      closeOnClick: true
    }],
    showDeleteButton: true,
    handleDeleteItem: function handleDeleteItem() {
    },
    isDeletingItem: false,
    ref: chatCardRef,
    children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkKNTAARQFjs.StyledChatCard, {
      onClick: handleCardClick,
      isCardSelected,
      showPointer: !!handleClick,
      children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _avatars.AvatarWithPlaceholder, {
        sx: {
          alignSelf: "center",
          justifySelf: "center"
        },
        width: 48,
        height: 48,
        src: avatar
      }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, {
        display: "grid",
        gridTemplateRows: "repeat(2, minmax(0, 1fr))",
        children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _typographies.TypographyWithEllipsis, {
          variant: "subtitle2",
          children: title
        }), lastMessage && lastMessageTime ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, {
          display: "grid",
          gridTemplateColumns: "min-content min-content auto",
          alignItems: "center",
          children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
            variant: "caption",
            color: "text.secondary",
            noWrap: true,
            children: _chunk5YP3QLWRjs.formatDate.call(void 0, lastMessageTime)
          }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, {
            sx: {
              display: "inline-block",
              height: "6px",
              width: "6px",
              borderRadius: "50%",
              backgroundColor: "text.disabled",
              marginX: "8px"
            }
          }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
            variant: "caption",
            color: "text.secondary",
            noWrap: true,
            sx: {
              overflow: "hidden",
              textOverflow: "ellipsis"
            },
            children: lastMessage
          })]
        }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {})]
      }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Badge, _objectSpread({
        sx: {
          marginRight: "12px",
          justifySelf: "center",
          display: "flex",
          alignItems: "center"
        },
        badgeContent: ((_unreadMessagesCountF3 = unreadMessagesCountFragment.unreadMessages) === null || _unreadMessagesCountF3 === void 0 ? void 0 : _unreadMessagesCountF3.count) || "",
        color: "error",
        max: 99,
        invisible: !hasUnreadMessages
      }, BadgeProps))]
    }, "room-".concat(roomRef.id))
  });
};
var ChatRoomItem_default = ChatRoomItem;



exports.ChatRoomItem_default = ChatRoomItem_default;
//# sourceMappingURL=chunk-KRRJ7PJ6.js.map