'use client'
import { __awaiter } from '../../../../../_virtual/_tslib.js';
import '@dynamic-labs-sdk/client';
import '@dynamic-labs/utils';
import '@dynamic-labs/sdk-api-core';
import '@dynamic-labs-sdk/client/core';
import 'react';
import 'eventemitter3';
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 '../../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-wallet/browser-wallet-client';
import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
import '../../../store/state/primaryWalletId/primaryWalletId.js';
import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
import '../../functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';
import { dynamicEvents } from '../../../events/dynamicEvents.js';
import '@dynamic-labs/locale';
import { verifyMergeUsers } from '../../../data/api/user/user.js';
import '../../../context/DynamicContext/useDynamicContext/useDynamicContext.js';
import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js';
import { useInternalUserWallets } from '../../../context/UserWalletsContext/UserWalletsContext.js';

const useMergeUserAccounts = () => {
    const { environmentId, setShowAuthFlow, selectedWalletConnector } = useInternalDynamicContext();
    const { addedWalletsIds } = useInternalUserWallets();
    const mergeUserAccounts = (mergeConflictResolutions) => __awaiter(void 0, void 0, void 0, function* () {
        const user = yield verifyMergeUsers(environmentId, mergeConflictResolutions);
        const walletId = user.lastVerifiedCredentialId;
        if (walletId) {
            addedWalletsIds.current.push(walletId);
        }
        const accounts = yield (selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.getConnectedAccounts());
        if (accounts === null || accounts === void 0 ? void 0 : accounts.length) {
            dynamicEvents.emit('triggerComputePrimaryWalletMultiWalletStateFromAccounts', { accounts });
        }
        setShowAuthFlow(false);
    });
    return {
        mergeUserAccounts,
    };
};

export { useMergeUserAccounts };
