import { ExternalActionId as e } from "../../types/external-action.types.mjs";
import { MessagesFromOffscreen as t } from "../../types/offscreen.types.mjs";
import "../../types/index.mjs";
import { transactionErrorCodes as n } from "../../error-handling/error-codes.constants.mjs";
import { caseInsensitiveEqual as r } from "../utils/caseInsensitive.utils.mjs";
import { Logger as i } from "../../error-handling/logger.mjs";
import "../../error-handling/index.mjs";
import { getFeeStructure as a } from "../pre-transaction/getFeeStructure.mjs";
import "../pre-transaction/index.mjs";
import { convertEmporiumOpToCallInfo as o } from "../utils/convertEmporiumOpToCallInfo.mjs";
import { postToOffscreen as s } from "../utils/postToOffscreen.mjs";
import "../utils/index.mjs";
//#region libs/shared/common/src/functions/auto-deposit-back-helpers/select-gas-token.ts
var c = async (c, l, u, d, f, p, m, h, g) => {
	try {
		if (!((p.find(({ erc20Token: e }) => r(e.erc20TokenAddress, c))?.totalUsdBalance ?? 0) >= l)) {
			let i = p.find((e) => e.totalUsdBalance <= l ? !1 : d.find(({ erc20TokenAddress: t }) => r(t, e.erc20Token.erc20TokenAddress)) ? e.publicUsdBalance > l : !0);
			if (!i) {
				s(t.AutoShieldTxStatus, { message: n.AUTO_SHIELD_INSUFFICIENT_GAS });
				return;
			}
			c = i.erc20Token.erc20TokenAddress, m = await a(u, c, h, e.Emporium, f.map((e) => o(e, g, u)));
		}
		return {
			feeToken: c,
			feeStructure: m
		};
	} catch (e) {
		i.error("selectGasToken error", { error: e });
		return;
	}
};
//#endregion
export { c as selectGasToken };
