import { useState } from 'react';
import { ConnectionHandler, ConnectionState } from '@sendbird/chat';
import { useSendbirdStateContext } from '../useSendbirdStateContext.js';
import { u as uuidv4 } from '../chunks/bundle-0P_11xTV.js';
import '../withSendbird.js';
import '../chunks/bundle-BL7mChau.js';

var useConnectionState = function () {
    var stores = useSendbirdStateContext().stores;
    var sdkStore = stores.sdkStore;
    var sdk = sdkStore.sdk;
    var _a = useState(sdk.connectionState), connectionState = _a[0], setConnectionState = _a[1];
    sdk.addConnectionHandler(uuidv4(), 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 connectionState;
};

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