"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _chunkGLYD52KYjs = require('./chunk-GLYD52KY.js');


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


var _chunkMYGO2IQXjs = require('./chunk-MYGO2IQX.js');

// tmp-babel/messages/common/utils.js
var _authentication = require('@baseapp-frontend/authentication');
var _reactrelay = require('react-relay');
var _relayconnectionhandlerplus = require('relay-connection-handler-plus'); var _relayconnectionhandlerplus2 = _interopRequireDefault(_relayconnectionhandlerplus);
var useGroupNameAndAvatar = function useGroupNameAndAvatar2(headerRef) {
  var _header$image;
  var header = _reactrelay.useFragment.call(void 0, _chunkGLYD52KYjs.GroupTitleFragment, headerRef);
  return {
    title: header === null || header === void 0 ? void 0 : header.title,
    avatar: header === null || header === void 0 || (_header$image = header.image) === null || _header$image === void 0 ? void 0 : _header$image.url
  };
};
var useRoomNameAndAvatar = function useRoomNameAndAvatar2(headerRef) {
  var _otherParticipant$nod, _otherParticipant$nod2;
  var _useCurrentProfile = _authentication.useCurrentProfile.call(void 0, ), currentProfile = _useCurrentProfile.currentProfile;
  var header = _reactrelay.useFragment.call(void 0, _chunkK3NX7MOXjs.RoomTitleFragment, headerRef);
  if (!(header !== null && header !== void 0 && header.participants)) {
    return {
      title: "Error: No participants"
    };
  }
  var otherParticipant = header.participants.edges.find(function(edge) {
    var _edge$node, _edge$node2;
    return (edge === null || edge === void 0 || (_edge$node = edge.node) === null || _edge$node === void 0 || (_edge$node = _edge$node.profile) === null || _edge$node === void 0 ? void 0 : _edge$node.id) && (edge === null || edge === void 0 || (_edge$node2 = edge.node) === null || _edge$node2 === void 0 || (_edge$node2 = _edge$node2.profile) === null || _edge$node2 === void 0 ? void 0 : _edge$node2.id) !== (currentProfile === null || currentProfile === void 0 ? void 0 : currentProfile.id);
  });
  return {
    title: otherParticipant === null || otherParticipant === void 0 || (_otherParticipant$nod = otherParticipant.node) === null || _otherParticipant$nod === void 0 || (_otherParticipant$nod = _otherParticipant$nod.profile) === null || _otherParticipant$nod === void 0 ? void 0 : _otherParticipant$nod.name,
    avatar: otherParticipant === null || otherParticipant === void 0 || (_otherParticipant$nod2 = otherParticipant.node) === null || _otherParticipant$nod2 === void 0 || (_otherParticipant$nod2 = _otherParticipant$nod2.profile) === null || _otherParticipant$nod2 === void 0 || (_otherParticipant$nod2 = _otherParticipant$nod2.image) === null || _otherParticipant$nod2 === void 0 ? void 0 : _otherParticipant$nod2.url
  };
};
var useNameAndAvatar = function useNameAndAvatar2(roomHeader) {
  var roomNameAndAvatar = useRoomNameAndAvatar(roomHeader);
  var groupNameAndAvatar = useGroupNameAndAvatar(roomHeader);
  if (roomHeader.isGroup) return groupNameAndAvatar;
  return roomNameAndAvatar;
};
var getParticipantCountString = function getParticipantCountString2(participantCount) {
  if (participantCount !== void 0 && participantCount !== null) {
    return "".concat(participantCount, " member").concat(participantCount !== 1 ? "s" : "");
  }
  return void 0;
};
var getChatRoomConnections = function getChatRoomConnections2(store, profileId, filter) {
  var storyRecord = store.get(profileId);
  if (storyRecord) {
    return _relayconnectionhandlerplus2.default.getConnections(storyRecord, "roomsList_chatRooms", filter);
  }
  return [];
};
var useCheckIsAdmin = function useCheckIsAdmin2(participants) {
  var _participants$edges, _me$node, _participants$edges2;
  var _useCurrentProfile2 = _authentication.useCurrentProfile.call(void 0, ), currentProfile = _useCurrentProfile2.currentProfile;
  var me = participants === null || participants === void 0 || (_participants$edges = participants.edges) === null || _participants$edges === void 0 ? void 0 : _participants$edges.find(function(edge) {
    var _edge$node3;
    return (edge === null || edge === void 0 || (_edge$node3 = edge.node) === null || _edge$node3 === void 0 || (_edge$node3 = _edge$node3.profile) === null || _edge$node3 === void 0 ? void 0 : _edge$node3.id) === (currentProfile === null || currentProfile === void 0 ? void 0 : currentProfile.id);
  });
  var isAdmin = (me === null || me === void 0 || (_me$node = me.node) === null || _me$node === void 0 ? void 0 : _me$node.role) === _chunkMYGO2IQXjs.CHAT_ROOM_PARTICIPANT_ROLES.admin;
  var isSoleAdmin = isAdmin && (participants === null || participants === void 0 || (_participants$edges2 = participants.edges) === null || _participants$edges2 === void 0 ? void 0 : _participants$edges2.filter(function(edge) {
    var _edge$node4;
    return (edge === null || edge === void 0 || (_edge$node4 = edge.node) === null || _edge$node4 === void 0 ? void 0 : _edge$node4.role) === _chunkMYGO2IQXjs.CHAT_ROOM_PARTICIPANT_ROLES.admin;
  }).length) === 1;
  return {
    isAdmin,
    isSoleAdmin
  };
};







exports.useGroupNameAndAvatar = useGroupNameAndAvatar; exports.useNameAndAvatar = useNameAndAvatar; exports.getParticipantCountString = getParticipantCountString; exports.getChatRoomConnections = getChatRoomConnections; exports.useCheckIsAdmin = useCheckIsAdmin;
//# sourceMappingURL=chunk-UYBEH4KA.js.map