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

var _chunk7M2ERNZFjs = require('./chunk-7M2ERNZF.js');


var _chunk36U36PVDjs = require('./chunk-36U36PVD.js');


var _chunkJ4J4IBUJjs = require('./chunk-J4J4IBUJ.js');


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


var _chunkPQMT7VJNjs = require('./chunk-PQMT7VJN.js');


var _chunkM4XNAJAZjs = require('./chunk-M4XNAJAZ.js');


var _chunk22ZA7RAXjs = require('./chunk-22ZA7RAX.js');



var _chunkECBMCATXjs = require('./chunk-ECBMCATX.js');

// tmp-babel/messages/web/GroupChatDetails/index.js
var _react = require('react');
var _authentication = require('@baseapp-frontend/authentication');
var _displays = require('@baseapp-frontend/design-system/components/web/displays');
var _material = require('@mui/material');
var _reactrelay = require('react-relay');
var _reactvirtuoso = require('react-virtuoso');
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);
}
var _excluded = ["onBackButtonClicked", "Header", "HeaderProps"];
function _objectWithoutProperties(e, t) {
  if (null == e) return {};
  var o, r, i = _objectWithoutPropertiesLoose(e, t);
  if (Object.getOwnPropertySymbols) {
    var n = Object.getOwnPropertySymbols(e);
    for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
  }
  return i;
}
function _objectWithoutPropertiesLoose(r, e) {
  if (null == r) return {};
  var t = {};
  for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
    if (-1 !== e.indexOf(n)) continue;
    t[n] = r[n];
  }
  return t;
}
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 GroupChatDetails = function GroupChatDetails2(_ref) {
  var _currentProfile$id;
  var _ref$Body = _ref.Body, Body = _ref$Body === void 0 ? _chunkJ4J4IBUJjs.Body_default : _ref$Body, _ref$BodyProps = _ref.BodyProps, BodyProps = _ref$BodyProps === void 0 ? {} : _ref$BodyProps, _ref$Header = _ref.Header, Header = _ref$Header === void 0 ? _chunk7M2ERNZFjs.Header_default : _ref$Header, _ref$HeaderProps = _ref.HeaderProps, HeaderProps = _ref$HeaderProps === void 0 ? {} : _ref$HeaderProps, onBackButtonClicked = _ref.onBackButtonClicked, onEditButtonClicked = _ref.onEditButtonClicked, _ref$ProfileCard = _ref.ProfileCard, ProfileCard = _ref$ProfileCard === void 0 ? _chunk36U36PVDjs.ProfileCard_default : _ref$ProfileCard, _ref$ProfileCardProps = _ref.ProfileCardProps, ProfileCardProps = _ref$ProfileCardProps === void 0 ? {} : _ref$ProfileCardProps, queryRef = _ref.queryRef, _ref$VirtuosoProps = _ref.VirtuosoProps, VirtuosoProps = _ref$VirtuosoProps === void 0 ? {} : _ref$VirtuosoProps;
  var _usePreloadedQuery = _reactrelay.usePreloadedQuery.call(void 0, _chunkM4XNAJAZjs.GroupDetailsQuery, queryRef), group = _usePreloadedQuery.chatRoom;
  var _useCurrentProfile = _authentication.useCurrentProfile.call(void 0, ), currentProfile = _useCurrentProfile.currentProfile;
  var _useGroupNameAndAvata = _chunkECBMCATXjs.useGroupNameAndAvatar.call(void 0, group), avatar = _useGroupNameAndAvata.avatar, title = _useGroupNameAndAvata.title;
  var profileId = (_currentProfile$id = currentProfile === null || currentProfile === void 0 ? void 0 : currentProfile.id) !== null && _currentProfile$id !== void 0 ? _currentProfile$id : "";
  var connections = group !== null && group !== void 0 && group.id ? [_reactrelay.ConnectionHandler.getConnectionID(group.id, "ChatRoom_participants")] : [];
  _chunkPQMT7VJNjs.useRoomListSubscription.call(void 0, {
    profileId,
    connections,
    onRemoval: onBackButtonClicked
  });
  var _usePaginationFragmen = _reactrelay.usePaginationFragment.call(void 0, _chunk22ZA7RAXjs.MembersListFragment, group), data = _usePaginationFragmen.data, loadNext = _usePaginationFragmen.loadNext, isLoadingNext = _usePaginationFragmen.isLoadingNext, hasNext = _usePaginationFragmen.hasNext;
  var members = data === null || data === void 0 ? void 0 : data.participants;
  var _useCheckIsAdmin = _chunkECBMCATXjs.useCheckIsAdmin.call(void 0, members), isAdmin = _useCheckIsAdmin.isAdmin, isSoleAdmin = _useCheckIsAdmin.isSoleAdmin;
  var renderLoadingState = function renderLoadingState2() {
    if (!isLoadingNext) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, {
      sx: {
        paddingTop: 3
      }
    });
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _displays.LoadingState, {
      sx: {
        paddingTop: 3,
        paddingBottom: 1
      },
      CircularProgressProps: {
        size: 15
      },
      "aria-label": "loading more profiles"
    });
  };
  var _useState = _react.useState.call(void 0, void 0), _useState2 = _slicedToArray(_useState, 2), removingParticipantId = _useState2[0], setRemovingParticipantId = _useState2[1];
  var removingParticipantName = _react.useRef.call(void 0, void 0);
  var initiateRemoval = function initiateRemoval2(id, name) {
    setRemovingParticipantId(id);
    removingParticipantName.current = name;
  };
  var handleRemoveDialogClose = function handleRemoveDialogClose2() {
    setRemovingParticipantId(void 0);
    removingParticipantName.current = void 0;
  };
  var renderItem = function renderItem2(item) {
    if (item.node) {
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ProfileCard, _objectSpread({
        groupMember: item.node,
        initiateRemoval,
        hasAdminPermissions: isAdmin
      }, ProfileCardProps));
    }
    return null;
  };
  var renderMembers = function renderMembers2() {
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactvirtuoso.Virtuoso, _objectSpread({
      data: members === null || members === void 0 ? void 0 : members.edges,
      itemContent: function itemContent(_index, item) {
        return renderItem(item);
      },
      style: {
        scrollbarWidth: "none"
      },
      components: {
        Footer: renderLoadingState
      },
      endReached: function endReached() {
        if (hasNext) {
          loadNext(5);
        }
      }
    }, VirtuosoProps));
  };
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, {
    children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk66E2PMX6js.LeaveGroupDialog_default, {
      profileId,
      roomId: group === null || group === void 0 ? void 0 : group.id,
      open: !!removingParticipantId,
      removingParticipantId: removingParticipantId !== null && removingParticipantId !== void 0 ? removingParticipantId : "",
      onClose: handleRemoveDialogClose,
      isSoleAdmin
    }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Header, _objectSpread({
      onBackButtonClicked,
      onEditButtonClicked,
      shouldDisplayEditButton: isAdmin
    }, HeaderProps)), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Body, _objectSpread(_objectSpread({
      title,
      avatar,
      participantsCount: group === null || group === void 0 ? void 0 : group.participantsCount
    }, BodyProps), {}, {
      children: renderMembers()
    }))]
  });
};
var SuspendedGroupDetails = function SuspendedGroupDetails2(_ref2) {
  var onBackButtonClicked = _ref2.onBackButtonClicked, _ref2$Header = _ref2.Header, Header = _ref2$Header === void 0 ? _chunk7M2ERNZFjs.Header_default : _ref2$Header, _ref2$HeaderProps = _ref2.HeaderProps, HeaderProps = _ref2$HeaderProps === void 0 ? {} : _ref2$HeaderProps, props = _objectWithoutProperties(_ref2, _excluded);
  return (
    // Displays a 'preliminary' header and a spinner below
    // Header has "Group Details" label and back button, but no edit button (appears if the group details are loaded and current user has admin permissions)
    /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Suspense, {
      fallback: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, {
        children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Header, _objectSpread({
          onBackButtonClicked,
          shouldDisplayEditButton: false
        }, HeaderProps)), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _displays.LoadingState, {})]
      }),
      children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, GroupChatDetails, _objectSpread({
        onBackButtonClicked
      }, props))
    })
  );
};
var GroupChatDetails_default = SuspendedGroupDetails;



exports.GroupChatDetails_default = GroupChatDetails_default;
//# sourceMappingURL=chunk-2TTY3FC4.js.map