'use client'
'use strict';

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

/**
 * Block explorer URL patterns for different chains
 * This mapping allows for easy configuration and extension of transaction link formats
 */
/**
 * Predefined patterns for known block explorers
 * Add new patterns here as needed for different chains
 */
const BLOCK_EXPLORER_PATTERNS = [
    {
        description: 'TRON - Uses hash fragment format',
        domain: 'tronscan.org',
        generateUrl: (baseUrl, hash) => {
            const url = new URL(baseUrl);
            return `${url.origin}/#/transaction/${hash}`;
        },
    },
    {
        // Provable hosts both mainnet (`explorer.provable.com`) and testnet
        //  (`testnet.explorer.provable.com`). Matching the bare
        //  `explorer.provable.com` substring covers both subdomains.
        description: 'Aleo (Provable) - Uses /transaction/{hash}',
        domain: 'explorer.provable.com',
        generateUrl: (baseUrl, hash) => {
            const url = new URL(baseUrl);
            url.pathname = `/transaction/${hash}`;
            return url.toString();
        },
    },
    {
        // mempool.space scopes networks by path (/testnet, /signet); the network
        // segment must be preserved or testnet links resolve to mainnet.
        description: 'mempool.space - keeps the network path segment',
        domain: 'mempool.space',
        generateUrl: (baseUrl, hash) => {
            const url = new URL(baseUrl);
            const basePath = url.pathname.replace(/\/$/, '');
            url.pathname = `${basePath}/tx/${hash}`;
            return url.toString();
        },
    },
    {
        // The Midnight explorer indexes by the canonical transaction hash and
        // serves detail pages at `/transactions/{hash}`. Matching the bare
        // `midnight.network` substring covers the preview/testnet subdomains.
        description: 'Midnight - Uses /transactions/{hash}',
        domain: 'midnight.network',
        generateUrl: (baseUrl, hash) => {
            const url = new URL(baseUrl);
            url.pathname = `/transactions/${hash}`;
            return url.toString();
        },
    },
];
/**
 * Default pattern for standard block explorers
 * Used when no specific pattern matches
 */
const DEFAULT_PATTERN = {
    description: 'Standard format used by most block explorers',
    domain: '*',
    generateUrl: (baseUrl, hash) => {
        const url = new URL(baseUrl);
        url.pathname = `/tx/${hash}`;
        return url.toString();
    },
};
/**
 * Block explorer domains known to support the /op/{userOpHash} route
 * for ERC-4337 UserOperation lookups.
 *
 * Only Blockscout-based explorers are known to support this route.
 * Etherscan-family explorers (etherscan.io, polygonscan.com, etc.)
 * return 404 for /op/ paths. JiffyScan uses /userOpHash/ instead.
 *
 * Customers can extend this list via the transaction-confirmation view override.
 */
const USER_OP_SUPPORTED_EXPLORER_DOMAINS = [
    // Blockscout-hosted instances (covers *.blockscout.com subdomains)
    'blockscout.com',
    // Blockscout instances on custom domains
    'scrollscan.com',
    'explorer.optimism.io',
];
/**
 * Check whether a block explorer URL supports the /op/{hash} route.
 * Matches against the built-in list and any additional domains provided
 * by the customer via the transaction-confirmation view override.
 */
const supportsUserOpPath = (blockExplorerUrl, additionalDomains) => {
    const allDomains = additionalDomains
        ? [...USER_OP_SUPPORTED_EXPLORER_DOMAINS, ...additionalDomains]
        : USER_OP_SUPPORTED_EXPLORER_DOMAINS;
    return allDomains.some((domain) => blockExplorerUrl.includes(domain));
};
/**
 * Find the appropriate pattern for a given block explorer URL
 */
const findBlockExplorerPattern = (blockExplorerUrl) => {
    const pattern = BLOCK_EXPLORER_PATTERNS.find((pattern) => blockExplorerUrl.includes(pattern.domain));
    return pattern || DEFAULT_PATTERN;
};

exports.BLOCK_EXPLORER_PATTERNS = BLOCK_EXPLORER_PATTERNS;
exports.DEFAULT_PATTERN = DEFAULT_PATTERN;
exports.USER_OP_SUPPORTED_EXPLORER_DOMAINS = USER_OP_SUPPORTED_EXPLORER_DOMAINS;
exports.findBlockExplorerPattern = findBlockExplorerPattern;
exports.supportsUserOpPath = supportsUserOpPath;
