'use client'
import { __awaiter } from '../../../../../_virtual/_tslib.js';
import { InvalidExternalAuthError } from '@dynamic-labs-sdk/client';
import { SandboxMaximumThresholdReachedError, DynamicError } from '@dynamic-labs/utils';
import '@dynamic-labs-sdk/client/core';
import '@dynamic-labs/sdk-api-core';
import '../../../client/client.js';
import 'react';
import '../../../config/ApiEndpoint.js';
import '@dynamic-labs/iconic';
import '@dynamic-labs/wallet-connector-core';
import 'react/jsx-runtime';
import '../../../context/ViewContext/ViewContext.js';
import '../../../shared/logger.js';
import '@dynamic-labs/wallet-book';
import '../../../utils/constants/colors.js';
import '../../../utils/constants/values.js';
import '../../../shared/consts/index.js';
import '@dynamic-labs/multi-wallet';
import 'react-international-phone';
import '../../../store/state/nonce/nonce.js';
import { sdkApi } from '../api.js';
import { logResponseError } from '../utils.js';
import '@dynamic-labs/locale';
import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
import '../../../store/state/primaryWalletId/primaryWalletId.js';
import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
import '../../../events/dynamicEvents.js';
import { storeTokenAndUser } from '../../../client/extension/storeTokenAndUser/storeTokenAndUser.js';

/**
 * @deprecated Use `signInWithExternalJwt` instead.
 * This currently does not work.
 */
const externalAuthVerify = (_a) => __awaiter(void 0, [_a], void 0, function* ({ environmentId, externalJwt, }) {
    try {
        /* istanbul ignore next */
        const response = (yield sdkApi().externalAuthVerify({
            environmentId,
            externalAuthSigninRequest: {
                jwt: externalJwt,
            },
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
        }));
        return storeTokenAndUser(response);
    }
    catch (e) {
        const data = yield logResponseError(e, 'Error verifying external JWT');
        if (data.code === 'invalid_external_auth') {
            throw new InvalidExternalAuthError({
                cause: data,
            });
        }
        if (data.error.code === 'sandbox_maximum_threshold_reached') {
            throw new SandboxMaximumThresholdReachedError(data.error.message);
        }
        throw new DynamicError(data.error);
    }
});

export { externalAuthVerify };
