'use client'
import { __awaiter } from '../../../../../_virtual/_tslib.js';
import { isAccountAbstractionConnector } from '@dynamic-labs/wallet-connector-core';
import { supportsUserOpPath, findBlockExplorerPattern } from './blockExplorerPatterns.js';

const USER_OP_PATH_PREFIX = '/op/';
const getTransactionLink = (_a) => __awaiter(void 0, [_a], void 0, function* ({ walletConnector, transactionHash, userOpSupportedExplorers, }) {
    try {
        if (!walletConnector) {
            return undefined;
        }
        const [blockExplorerUrl] = yield walletConnector.getBlockExplorerUrlsForCurrentNetwork();
        if (!blockExplorerUrl)
            return undefined;
        // AA connectors (e.g. ZeroDev) return a userOp hash, which should
        // link to /op/{hash} on supported block explorers instead of /tx/{hash}.
        // Not all block explorers support the /op/ route, so we check against
        // a known list plus any customer-provided overrides.
        if (isAccountAbstractionConnector(walletConnector) &&
            supportsUserOpPath(blockExplorerUrl, userOpSupportedExplorers)) {
            const url = new URL(blockExplorerUrl);
            url.pathname = `${USER_OP_PATH_PREFIX}${transactionHash}`;
            return url.toString();
        }
        // Find the appropriate pattern for this block explorer
        const pattern = findBlockExplorerPattern(blockExplorerUrl);
        // Generate the transaction URL using the pattern
        return pattern.generateUrl(blockExplorerUrl, transactionHash);
    }
    catch (error) {
        return undefined;
    }
});

export { getTransactionLink };
