'use client'
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _tslib = require('../../../../../_virtual/_tslib.cjs');
var React = require('react');
var client = require('@dynamic-labs-sdk/client');
var dynamicEvents = require('../../../events/dynamicEvents.cjs');
require('@dynamic-labs-sdk/client/core');
require('@dynamic-labs/sdk-api-core');
require('eventemitter3');
require('@dynamic-labs/utils');
require('../../../config/ApiEndpoint.cjs');
require('@dynamic-labs/iconic');
require('@dynamic-labs/wallet-connector-core');
require('react/jsx-runtime');
require('../../../context/ViewContext/ViewContext.cjs');
require('../../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
require('../../constants/colors.cjs');
require('../../constants/values.cjs');
require('../../../shared/consts/index.cjs');
require('@dynamic-labs/multi-wallet');
require('react-international-phone');
require('../../../store/state/nonce/nonce.cjs');
require('@dynamic-labs-wallet/browser-wallet-client');
require('@dynamic-labs/locale');
require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
require('../../functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.cjs');
var storeTokenAndUser = require('../../../client/extension/storeTokenAndUser/storeTokenAndUser.cjs');
var useUserAuth = require('../useUserAuth/useUserAuth.cjs');

/**
 * Authenticate passkey for MFA
 *
 * @returns Function to authenticate with a passkey for MFA
 *
 * @example
 * ```tsx
 * const App = () => {
 *   const authenticatePasskeyMFA = useAuthenticatePasskeyMFA();
 *
 *   // Optional: creates a single-use MFA token
 *   const createMfaToken = { singleUse: true };
 *
 *   return (
 *     <button
 *       onClick={() => authenticatePasskeyMFA({ createMfaToken })}
 *     >
 *       Authenticate passkey
 *     </button>
 *  );
 * }
 */
const useAuthenticatePasskeyMFA = () => {
    const { completeAuth } = useUserAuth.useUserAuth({});
    return React.useCallback((props) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
        let mfaToken = undefined;
        yield completeAuth({
            updateJwtFunction: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
                var _a;
                const response = yield client.authenticatePasskeyMFA(props);
                // When requestedScopes is provided the response contains an elevated
                // access token. storeTokenAndUser routes through updateAuthFromVerifyResponse
                // which stores it in client state so getElevatedAccessToken can retrieve it.
                if ((_a = props === null || props === void 0 ? void 0 : props.requestedScopes) === null || _a === void 0 ? void 0 : _a.length) {
                    storeTokenAndUser.storeTokenAndUser(response);
                }
                // eslint-disable-next-line prefer-destructuring
                mfaToken = response.mfaToken;
                dynamicEvents.dynamicEvents.emit('mfaCompletionSuccess', {
                    mfaToken: response.mfaToken,
                });
                return {
                    isEmailVerificationRequired: false,
                    isSmsVerificationRequired: false,
                    missingFields: [],
                    // VerifyResponse is compatible with UpdateSelfResponse for MFA flows:
                    // Both types have: expiresAt, jwt, minifiedJwt, user (used in useUserAuth.ts:329-332)
                    updateUserProfileResponse: response,
                };
            }),
        });
        return mfaToken;
    }), [completeAuth]);
};

exports.useAuthenticatePasskeyMFA = useAuthenticatePasskeyMFA;
