'use client'
import { __awaiter } from '../../../../../_virtual/_tslib.js';
import { useCallback } from 'react';
import '@dynamic-labs-sdk/client/core';
import '@dynamic-labs/sdk-api-core';
import '../../../client/client.js';
import '@dynamic-labs-sdk/client';
import '../../../config/ApiEndpoint.js';
import '@dynamic-labs/iconic';
import '@dynamic-labs/wallet-connector-core';
import 'react/jsx-runtime';
import '../../../context/ViewContext/ViewContext.js';
import { logger } from '../../../shared/logger.js';
import '@dynamic-labs/wallet-book';
import '@dynamic-labs/utils';
import '../../constants/colors.js';
import '../../constants/values.js';
import '../../../shared/consts/index.js';
import '@dynamic-labs/multi-wallet';
import 'react-international-phone';
import '../../../store/state/nonce/nonce.js';
import '@dynamic-labs/locale';
import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
import '../../../store/state/primaryWalletId/primaryWalletId.js';
import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
import { getClientSessionPublicKey, getClientSessionSignature } from '../../functions/clientSessionKeys/getClientSessionKeys.js';
import '../../../events/dynamicEvents.js';
import { useOnboardingCompleteUser } from '../../../client/extension/user/useOnboardingCompleteUser/useOnboardingCompleteUser.js';
import { usePromise } from '../usePromise/usePromise.js';

const useClientSessionKeys = () => {
    const user = useOnboardingCompleteUser();
    const sessionPublicKey = getClientSessionPublicKey();
    const getSignedSessionId = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
        if (!(user === null || user === void 0 ? void 0 : user.sessionId) || !sessionPublicKey) {
            throw new Error('Session ID and public key are required');
        }
        const result = yield getClientSessionSignature({
            sessionId: user === null || user === void 0 ? void 0 : user.sessionId,
        });
        logger.instrument('[SessionChaining] Generated session signature', {
            environmentId: user.projectEnvironmentId,
            key: 'generated_session_signature',
            sessionId: user.sessionId,
            sessionPublicKey,
            sessionSignature: result.sessionSignature,
            time: 0,
        });
        return result.sessionSignature;
    }), [user === null || user === void 0 ? void 0 : user.sessionId, sessionPublicKey]);
    const { data: sessionSignatureResult } = usePromise(getSignedSessionId, {
        deps: [user === null || user === void 0 ? void 0 : user.sessionId, sessionPublicKey],
        enabled: Boolean(user === null || user === void 0 ? void 0 : user.sessionId) && Boolean(sessionPublicKey),
        initialData: undefined,
        retries: 2,
    });
    return {
        getSignedSessionId,
        sessionPublicKey,
        sessionSignature: sessionSignatureResult,
    };
};

export { useClientSessionKeys };
