import { useState, useEffect } from 'react';
import { ConnectionHandler, ConnectionState } from '@sendbird/chat';
import { u as uuidv4 } from '../chunks/bundle-CTkGIdt8.js';
import { u as useSendbird } from '../chunks/bundle-I25ah_Bv.js';
import '../chunks/bundle-B8Grfnrx.js';
import '../chunks/bundle-C4OmfIXk.js';
import '../chunks/bundle-Ob7Cw3V-.js';
import '@sendbird/chat/groupChannel';
import '@sendbird/chat/openChannel';

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

export { useConnectionState };
//# sourceMappingURL=useConnectionState.js.map
