'use strict';

var React = require('react');
var SendbirdChat = require('@sendbird/chat');
var uuid = require('../chunks/bundle-BUGwK1WK.js');
var useSendbird = require('../chunks/bundle-LI9JjqG2.js');
require('../chunks/bundle-CxoFSSXv.js');
require('../chunks/bundle-AAO7jUU2.js');
require('../chunks/bundle-yU9Mr2pS.js');
require('@sendbird/chat/groupChannel');
require('@sendbird/chat/openChannel');

var useConnectionState = function () {
    var stores = useSendbird.useSendbird().state.stores;
    var sdkStore = stores.sdkStore;
    var sdk = sdkStore.sdk;
    var _a = React.useState(sdk.connectionState), connectionState = _a[0], setConnectionState = _a[1];
    React.useEffect(function () {
        var _a;
        var handlerId = uuid.uuidv4();
        (_a = sdk === null || sdk === void 0 ? void 0 : sdk.addConnectionHandler) === null || _a === void 0 ? void 0 : _a.call(sdk, handlerId, new SendbirdChat.ConnectionHandler({
            onConnected: function () { return setConnectionState(SendbirdChat.ConnectionState.OPEN); },
            onDisconnected: function () { return setConnectionState(SendbirdChat.ConnectionState.CLOSED); },
            onReconnectStarted: function () { return setConnectionState(SendbirdChat.ConnectionState.CONNECTING); },
            onReconnectSucceeded: function () { return setConnectionState(SendbirdChat.ConnectionState.OPEN); },
            onReconnectFailed: function () { return setConnectionState(SendbirdChat.ConnectionState.CLOSED); },
        }));
        return function () {
            var _a;
            (_a = sdk === null || sdk === void 0 ? void 0 : sdk.removeConnectionHandler) === null || _a === void 0 ? void 0 : _a.call(sdk, handlerId);
        };
    }, [sdk]);
    return connectionState;
};

exports.useConnectionState = useConnectionState;
//# sourceMappingURL=useConnectionState.js.map
