'use client'
/**
 * Returns an additional address of the given type. When a `network` tag is
 * provided (e.g. Midnight's 'mainnet' | 'preview'), the variant matching that
 * network is preferred, falling back to the first address of the type for
 * legacy/untagged wallets. Callers that don't pass `network` keep the previous
 * "first match" behavior.
 */
const getWalletAdditionalAddressByType = (type, wallet, network) => {
    var _a, _b, _c;
    const matches = (_b = (_a = wallet === null || wallet === void 0 ? void 0 : wallet.additionalAddresses) === null || _a === void 0 ? void 0 : _a.filter((address) => address.type === type)) !== null && _b !== void 0 ? _b : [];
    if (network) {
        const networkMatch = matches.find((address) => address.network === network);
        if (networkMatch)
            return networkMatch.address;
    }
    return (_c = matches[0]) === null || _c === void 0 ? void 0 : _c.address;
};

export { getWalletAdditionalAddressByType };
