"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = explorerUrl;
const ufo_1 = require("ufo");
const mcrypto_1 = require("@ocap/mcrypto");
const did_1 = require("@arcblock/did");
const config_1 = require("./config");
const util_1 = require("./util");
const { RoleType } = mcrypto_1.types;
const baseUrl = 'https://explorer.abtnetwork.io/explorer/';
function explorerUrl({ hash, asset, rollup, address, token, stake, chainId = '', }) {
    if ((0, util_1.isEVMChain)(chainId)) {
        const url = (0, util_1.getExplorerUrl)(chainId);
        if (hash) {
            return (0, ufo_1.joinURL)(url, `tx/${hash}`);
        }
        if (asset) {
            return (0, ufo_1.joinURL)(url, `token/${asset}`);
        }
        return (0, ufo_1.joinURL)(url, `address/${address}`);
    }
    const chain = config_1.arcChainConfig[chainId];
    const chainHost = chain === null || chain === void 0 ? void 0 : chain.defaultRPC;
    const host = chainHost ? `${chainHost}` : undefined;
    // rollup
    if (rollup && (0, did_1.toTypeInfo)(rollup).role === RoleType.ROLE_ROLLUP) {
        if (hash) {
            return (0, ufo_1.withQuery)((0, ufo_1.joinURL)(baseUrl, `rollups/${rollup}/moves/${hash}`), { host });
        }
        return (0, ufo_1.withQuery)((0, ufo_1.joinURL)(baseUrl, `rollups/${rollup}`), { host });
    }
    // asset
    if (asset) {
        return (0, ufo_1.withQuery)((0, ufo_1.joinURL)(baseUrl, `assets/${asset}`), { host });
    }
    // tx
    if (hash) {
        return (0, ufo_1.withQuery)((0, ufo_1.joinURL)(baseUrl, `txs/${hash}`), { host });
    }
    // tx
    if (token) {
        return (0, ufo_1.withQuery)((0, ufo_1.joinURL)(baseUrl, `tokens/${token}/tx`), { host });
    }
    if (stake) {
        return (0, ufo_1.withQuery)((0, ufo_1.joinURL)(baseUrl, `stakes/${stake}`), { host });
    }
    // account
    return (0, ufo_1.withQuery)((0, ufo_1.joinURL)(baseUrl, `accounts/${address}`), { host });
}
