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

var _chunkZEUAUHNKjs = require('./chunk-ZEUAUHNK.js');

// tmp-babel/messages/native/graphql/subscriptions/useMessagesListSubscription.js
var _react = require('react');
var _useAppStateSubscription = require('@baseapp-frontend/utils/hooks/useAppStateSubscription');
var _exporouter = require('expo-router');
var _reactrelay = require('react-relay');
var useMessagesListSubscription = function useMessagesListSubscription2(roomId, profileId, environment) {
  var disposableRef = _react.useRef.call(void 0, null);
  var connectionID = _react.useMemo.call(void 0, function() {
    return _reactrelay.ConnectionHandler.getConnectionID(roomId, "chatRoom_allMessages");
  }, [roomId]);
  var config = _react.useMemo.call(void 0, function() {
    return {
      subscription: _chunkZEUAUHNKjs.newMessageSubscription,
      variables: {
        roomId,
        profileId,
        connections: [connectionID]
      },
      onError: console.error
    };
  }, [roomId, profileId, connectionID]);
  var subscribe = _react.useCallback.call(void 0, function() {
    var _disposableRef$curren, _disposableRef$curren2;
    if (!roomId || !profileId) return;
    (_disposableRef$curren = disposableRef.current) === null || _disposableRef$curren === void 0 || (_disposableRef$curren2 = _disposableRef$curren.dispose) === null || _disposableRef$curren2 === void 0 || _disposableRef$curren2.call(_disposableRef$curren);
    disposableRef.current = _reactrelay.requestSubscription.call(void 0, environment, config);
  }, [roomId, profileId, environment, config]);
  var unsubscribe = _react.useCallback.call(void 0, function() {
    var _disposableRef$curren3, _disposableRef$curren4;
    (_disposableRef$curren3 = disposableRef.current) === null || _disposableRef$curren3 === void 0 || (_disposableRef$curren4 = _disposableRef$curren3.dispose) === null || _disposableRef$curren4 === void 0 || _disposableRef$curren4.call(_disposableRef$curren3);
    disposableRef.current = null;
  }, []);
  _exporouter.useFocusEffect.call(void 0, _react.useCallback.call(void 0, function() {
    subscribe();
    return function() {
      unsubscribe();
    };
  }, [subscribe, unsubscribe]));
  _useAppStateSubscription.useAppStateSubscription.call(void 0, function() {
    subscribe();
  });
};



exports.useMessagesListSubscription = useMessagesListSubscription;
//# sourceMappingURL=chunk-Z63SGYXM.js.map