'use client'
import { useState, useMemo, useCallback } from 'react';
import '@dynamic-labs-sdk/client/core';
import '@dynamic-labs/sdk-api-core';
import 'eventemitter3';
import '@dynamic-labs/utils';
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 '../../constants/colors.js';
import '../../constants/values.js';
import '../../../shared/consts/index.js';
import '../../../../../_virtual/_tslib.js';
import '@dynamic-labs/multi-wallet';
import 'react-international-phone';
import '../../../store/state/nonce/nonce.js';
import '@dynamic-labs-wallet/browser-wallet-client';
import '@dynamic-labs/locale';
import { useEnvironmentId } from '../../../store/state/dynamicContextProps/dynamicContextProps.js';
import '../../../store/state/primaryWalletId/primaryWalletId.js';
import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
import '../../functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';
import '../../../events/dynamicEvents.js';
import { useUser } from '../../../client/extension/user/useUser/useUser.js';

const INITIAL_STATE = {
    captchaRequired: false,
    error: null,
    isLoading: false,
    otpVerification: null,
};
const useStepUpState = () => {
    const user = useUser();
    const environmentId = useEnvironmentId();
    const [state, setState] = useState(INITIAL_STATE);
    const logContext = useMemo(() => ({ environmentId, userId: user === null || user === void 0 ? void 0 : user.id }), [environmentId, user === null || user === void 0 ? void 0 : user.id]);
    const resetState = useCallback(() => {
        setState(INITIAL_STATE);
    }, []);
    const setLoading = useCallback(() => {
        setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
    }, []);
    const setSuccess = useCallback((patch) => {
        setState((prev) => (Object.assign(Object.assign(Object.assign({}, prev), { error: null, isLoading: false }), patch)));
    }, []);
    const setError = useCallback((errorMessage) => {
        setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
        logger.error(errorMessage, logContext);
    }, [logContext]);
    return {
        logContext,
        resetState,
        setError,
        setLoading,
        setState,
        setSuccess,
        state,
    };
};

export { useStepUpState };
