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




var _chunkBYGB6ZY6js = require('./chunk-BYGB6ZY6.js');


var _chunkQRKOXN2Fjs = require('./chunk-QRKOXN2F.js');

// tmp-babel/messages/web/__shared__/LeaveGroupDialog/index.js
var _dialogs = require('@baseapp-frontend/design-system/components/web/dialogs');
var _utils = require('@baseapp-frontend/utils');
var _lab = require('@mui/lab');
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 LeaveGroupDialog = function LeaveGroupDialog2(_ref) {
  var customTitle = _ref.customTitle, customContent = _ref.customContent, onClose = _ref.onClose, open = _ref.open, profileId = _ref.profileId, removingParticipantId = _ref.removingParticipantId, roomId = _ref.roomId, _ref$isSoleAdmin = _ref.isSoleAdmin, isSoleAdmin = _ref$isSoleAdmin === void 0 ? false : _ref$isSoleAdmin;
  var _useUpdateChatRoomMut = _chunkQRKOXN2Fjs.useUpdateChatRoomMutation.call(void 0, ), _useUpdateChatRoomMut2 = _slicedToArray(_useUpdateChatRoomMut, 2), commit = _useUpdateChatRoomMut2[0], isMutationInFlight = _useUpdateChatRoomMut2[1];
  var _useNotification = _utils.useNotification.call(void 0, ), sendToast = _useNotification.sendToast;
  var getLeaveGroupDialogTextCopy = function getLeaveGroupDialogTextCopy2(type) {
    if (profileId === removingParticipantId) {
      if (isSoleAdmin) {
        return _chunkBYGB6ZY6js.LEAVE_GROUP_DIALOG_TEXT_COPY[_chunkBYGB6ZY6js.LEAVE_GROUP_DIALOG_TEXT_COPY_ACTION_KEYS.IS_LEAVING][_chunkBYGB6ZY6js.LEAVE_GROUP_DIALOG_TEXT_COPY_ROLE_KEYS.ADMIN][type];
      }
      return _chunkBYGB6ZY6js.LEAVE_GROUP_DIALOG_TEXT_COPY[_chunkBYGB6ZY6js.LEAVE_GROUP_DIALOG_TEXT_COPY_ACTION_KEYS.IS_LEAVING][_chunkBYGB6ZY6js.LEAVE_GROUP_DIALOG_TEXT_COPY_ROLE_KEYS.MEMBER][type];
    }
    return _chunkBYGB6ZY6js.LEAVE_GROUP_DIALOG_TEXT_COPY[_chunkBYGB6ZY6js.LEAVE_GROUP_DIALOG_TEXT_COPY_ACTION_KEYS.IS_REMOVING][_chunkBYGB6ZY6js.LEAVE_GROUP_DIALOG_TEXT_COPY_ROLE_KEYS.ADMIN][type];
  };
  var onRemoveConfirmed = function onRemoveConfirmed2() {
    if (!roomId || !profileId) return;
    commit({
      variables: {
        input: {
          roomId,
          profileId,
          removeParticipants: [removingParticipantId]
        },
        connections: [_reactrelay.ConnectionHandler.getConnectionID(roomId, "ChatRoom_participants")]
      },
      onCompleted: function onCompleted(response) {
        var _response$chatRoomUpd;
        if (removingParticipantId && removingParticipantId !== profileId && !(response !== null && response !== void 0 && (_response$chatRoomUpd = response.chatRoomUpdate) !== null && _response$chatRoomUpd !== void 0 && _response$chatRoomUpd.errors)) {
          sendToast("Member was successfully removed");
        }
        onClose();
      },
      onError: function onError(error) {
        sendToast(error.message, {
          type: "error"
        });
      }
    });
  };
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _dialogs.ConfirmDialog, {
    title: customTitle !== null && customTitle !== void 0 ? customTitle : getLeaveGroupDialogTextCopy(_chunkBYGB6ZY6js.LEAVE_GROUP_DIALOG_TEXT_COPY_TYPE_KEYS.TITLE),
    content: customContent !== null && customContent !== void 0 ? customContent : getLeaveGroupDialogTextCopy(_chunkBYGB6ZY6js.LEAVE_GROUP_DIALOG_TEXT_COPY_TYPE_KEYS.CONTENT),
    action: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lab.LoadingButton, {
      color: "error",
      onClick: onRemoveConfirmed,
      disabled: isMutationInFlight,
      loading: isMutationInFlight,
      children: removingParticipantId === profileId ? "Leave group" : "Remove"
    }),
    onClose,
    open
  });
};
var LeaveGroupDialog_default = LeaveGroupDialog;



exports.LeaveGroupDialog_default = LeaveGroupDialog_default;
//# sourceMappingURL=chunk-66E2PMX6.js.map