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

var _chunkBJ5FVFORjs = require('./chunk-BJ5FVFOR.js');




var _chunkJDKX3CSJjs = require('./chunk-JDKX3CSJ.js');


var _chunk66E2PMX6js = require('./chunk-66E2PMX6.js');


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


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


var _chunkDTIR4DVOjs = require('./chunk-DTIR4DVO.js');




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


var _chunkK3NX7MOXjs = require('./chunk-K3NX7MOX.js');

// tmp-babel/messages/web/ChatRoom/ChatRoomHeader/index.js
var _react = require('react');
var _authentication = require('@baseapp-frontend/authentication');
var _avatars = require('@baseapp-frontend/design-system/components/web/avatars');
var _buttons = require('@baseapp-frontend/design-system/components/web/buttons');
var _icons = require('@baseapp-frontend/design-system/components/web/icons');
var _images = require('@baseapp-frontend/design-system/components/web/images');
var _popovers = require('@baseapp-frontend/design-system/components/web/popovers');
var _typographies = require('@baseapp-frontend/design-system/components/web/typographies');
var _common = require('@baseapp-frontend/design-system/hooks/common');
var _web = require('@baseapp-frontend/design-system/hooks/web');
var _material = require('@mui/material');
var _reactrelay = require('react-relay');
var _jsxruntime = require('react/jsx-runtime');
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 ChatRoomHeader = function ChatRoomHeader2(_ref) {
  var _currentProfile$id, _currentProfile$id2;
  var isArchived = _ref.isArchived, participantsCount = _ref.participantsCount, roomTitleRef = _ref.roomTitleRef, onDisplayGroupDetailsClicked = _ref.onDisplayGroupDetailsClicked, roomId = _ref.roomId;
  var roomHeader = _reactrelay.useFragment.call(void 0, _chunkJM3OL3A2js.TitleFragment, roomTitleRef);
  var _useState = _react.useState.call(void 0, false), _useState2 = _slicedToArray(_useState, 2), open = _useState2[0], setOpen = _useState2[1];
  var _useCurrentProfile = _authentication.useCurrentProfile.call(void 0, ), currentProfile = _useCurrentProfile.currentProfile;
  var isUpToMd = _web.useResponsive.call(void 0, "up", "md");
  var _useChatRoom = _chunkDTIR4DVOjs.useChatRoom_default.call(void 0, ), resetChatRoom = _useChatRoom.resetChatRoom;
  var isGroup = roomHeader.isGroup;
  var _useNameAndAvatar = _chunkUYBEH4KAjs.useNameAndAvatar.call(void 0, roomHeader), title = _useNameAndAvatar.title, avatar = _useNameAndAvatar.avatar;
  var _useFragment = _reactrelay.useFragment.call(void 0, _chunkK3NX7MOXjs.RoomTitleFragment, roomHeader), participants = _useFragment.participants;
  var _useCheckIsAdmin = _chunkUYBEH4KAjs.useCheckIsAdmin.call(void 0, participants), isSoleAdmin = _useCheckIsAdmin.isSoleAdmin;
  var members = _chunkUYBEH4KAjs.getParticipantCountString.call(void 0, participantsCount);
  var popover = _common.usePopover.call(void 0, );
  var _useArchiveChatRoomMu = _chunkVPKGCVB7js.useArchiveChatRoomMutation.call(void 0, ), _useArchiveChatRoomMu2 = _slicedToArray(_useArchiveChatRoomMu, 2), commit = _useArchiveChatRoomMu2[0], isMutationInFlight = _useArchiveChatRoomMu2[1];
  var toggleArchiveChatroom = function toggleArchiveChatroom2() {
    popover.onClose();
    if (currentProfile !== null && currentProfile !== void 0 && currentProfile.id && roomId) {
      commit({
        variables: {
          input: {
            roomId,
            profileId: currentProfile.id,
            archive: !isArchived
          }
        }
      });
    }
  };
  var onChatRoomOptionsClicked = function onChatRoomOptionsClicked2(e) {
    e.stopPropagation();
    popover.onOpen(e);
  };
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, {
    children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk66E2PMX6js.LeaveGroupDialog_default, {
      open,
      onClose: function onClose() {
        return setOpen(false);
      },
      profileId: (_currentProfile$id = currentProfile === null || currentProfile === void 0 ? void 0 : currentProfile.id) !== null && _currentProfile$id !== void 0 ? _currentProfile$id : "",
      roomId,
      removingParticipantId: (_currentProfile$id2 = currentProfile === null || currentProfile === void 0 ? void 0 : currentProfile.id) !== null && _currentProfile$id2 !== void 0 ? _currentProfile$id2 : "",
      isSoleAdmin
    }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkJDKX3CSJjs.ChatHeaderContainer, {
      children: [isUpToMd ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {}) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkJDKX3CSJjs.BackButtonContainer, {
        children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _buttons.IconButton, {
          "aria-label": "return to chat room list",
          onClick: resetChatRoom,
          sx: {
            maxWidth: "fit-content"
          },
          children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _images.Iconify, {
            icon: "eva:arrow-ios-back-fill",
            width: 24
          })
        })
      }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkJDKX3CSJjs.ChatTitleContainer, {
        onClick: isGroup ? onDisplayGroupDetailsClicked : void 0,
        isClickable: isGroup,
        children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _avatars.AvatarWithPlaceholder, {
          className: "self-start justify-self-center",
          width: 32,
          height: 32,
          src: avatar,
          sx: {
            border: "none",
            alignSelf: "center"
          }
        }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, {
          children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _typographies.TypographyWithEllipsis, {
            component: "span",
            variant: "subtitle2",
            maxWidth: isUpToMd ? "300px" : "200px",
            sx: {
              "float": "left",
              clear: "left"
            },
            children: title
          }), isGroup && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
            component: "span",
            variant: "caption",
            sx: {
              "float": "left",
              clear: "left"
            },
            children: members
          })]
        }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, {
          children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _buttons.IconButton, {
            onClick: onChatRoomOptionsClicked,
            "aria-label": "Show chatroom options",
            children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _icons.ThreeDotsIcon, {
              sx: {
                fontSize: "24px"
              }
            })
          }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _popovers.Popover, {
            open: popover.open,
            onClose: popover.onClose,
            slotProps: {
              root: {
                onClick: function onClick(e) {
                  return e.stopPropagation();
                }
              }
            },
            children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkBJ5FVFORjs.ChatRoomOptions_default, {
              isArchived,
              isArchiveMutationInFlight: isMutationInFlight,
              isGroup,
              onArchiveClicked: toggleArchiveChatroom,
              onDetailsClicked: function onDetailsClicked() {
                popover.onClose();
                onDisplayGroupDetailsClicked();
              },
              onLeaveClicked: function onLeaveClicked() {
                popover.onClose();
                setOpen(true);
              }
            })
          })]
        })]
      })]
    })]
  });
};
var ChatRoomHeader_default = ChatRoomHeader;



exports.ChatRoomHeader_default = ChatRoomHeader_default;
//# sourceMappingURL=chunk-AEPQK527.js.map