'use client'
import { __awaiter } from '../../../../../_virtual/_tslib.js';
import { sdkApi } from '../api.js';
import '@dynamic-labs/iconic';
import '@dynamic-labs/wallet-connector-core';
import 'react';
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 '../../../utils/constants/colors.js';
import '../../../utils/constants/values.js';
import '@dynamic-labs/sdk-api-core';
import '../../../shared/consts/index.js';
import '@dynamic-labs/multi-wallet';
import { getAppOrigin } from '../../../utils/functions/getAppOrigin/getAppOrigin.js';
import 'react-international-phone';
import '../../../store/state/nonce/nonce.js';
import '@dynamic-labs-wallet/browser-wallet-client';
import '@dynamic-labs-sdk/client/core';
import 'eventemitter3';
import '@dynamic-labs-sdk/client';
import '../../../config/ApiEndpoint.js';
import '../../../events/dynamicEvents.js';
import '@dynamic-labs/locale';
import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
import '../../../store/state/primaryWalletId/primaryWalletId.js';
import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
import '../../../utils/functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';

const isMaliciousUrl = (_a) => __awaiter(void 0, [_a], void 0, function* ({ environmentId, url, }) {
    try {
        const request = {
            environmentId,
            scanWebsiteUrlRequest: { url },
        };
        const data = yield sdkApi().scanUrl(request);
        return data.isMalicious;
    }
    catch (error) {
        return undefined;
    }
});
const simulateBlockaidUserOperation = (_b) => __awaiter(void 0, [_b], void 0, function* ({ environmentId, userOperation, chainId, value, entryPoint, }) {
    try {
        const request = {
            environmentId,
            simulateUserOpRequest: {
                chainId,
                entryPoint: entryPoint.address,
                operation: userOperation,
                value: value,
            },
        };
        const transactionData = yield sdkApi().simulateUserOp(request);
        return transactionData;
    }
    catch (error) {
        logger.warn('simulateBlockaidUserOperation error', error);
        // when tx is not sponsored and blockaid is on, but user doesnt have enough gas
        if (error instanceof Error &&
            error.message.includes("AA21 didn't pay prefund")) {
            return {
                inAssets: [],
                outAssets: [],
                priceData: { nativeTokenUsdPrice: undefined },
                showTotalFiat: false,
            };
        }
        return undefined;
    }
});
const simulateBlockaidEVMTransaction = (_c) => __awaiter(void 0, [_c], void 0, function* ({ environmentId, chainId, from, to, value, data, }) {
    try {
        const request = {
            chainId,
            data,
            from,
            to,
            value,
        };
        const simulationRequest = {
            environmentId,
            simulateEVMTransactionRequest: request,
        };
        const transactionData = yield sdkApi().simulateEVMTransaction(simulationRequest);
        return transactionData;
    }
    catch (error) {
        logger.warn('simulateBlockaidEVMTransaction error', error);
        return undefined;
    }
});
const simulateBlockaidSVMTransaction = (_d) => __awaiter(void 0, [_d], void 0, function* ({ environmentId, chain, accountAddress, transactions, }) {
    var _e;
    try {
        const request = {
            environmentId,
            simulateSVMTransactionRequest: {
                accountAddress,
                chain,
                domain: (_e = getAppOrigin()) !== null && _e !== void 0 ? _e : 'https://example.com',
                // signAll works the same as sign, signAndSend, signAll
                method: 'signAllTransactions',
                transactions,
            },
        };
        const transactionData = yield sdkApi().simulateSVMTransaction(request);
        return transactionData;
    }
    catch (error) {
        logger.warn('simulateBlockaidSVMTransaction error', error);
        return undefined;
    }
});

export { isMaliciousUrl, simulateBlockaidEVMTransaction, simulateBlockaidSVMTransaction, simulateBlockaidUserOperation };
