import { caseInsensitiveEqual as e } from "../utils/caseInsensitive.utils.mjs";
import { getERC20Token as t } from "../utils/erc20tokenFunctions.mjs";
import { FeeOverTransactionValueError as n } from "../../error-handling/customErrors/FeeOverTransactionValueError.mjs";
import { Logger as r } from "../../error-handling/logger.mjs";
//#region libs/shared/common/src/functions/pre-transaction/merge-with-fee-structure.ts
var i = (i, a, o, s) => {
	r.log("amount changes before merge", { amountChanges: o });
	let c = a.findIndex((t) => e(t, s.feeToken));
	if (c === -1) {
		a.push(s.feeToken), o.push(-1n * s.flatFee), r.log("amount changes after merge", { amountChanges: o });
		return;
	}
	if (o[c] > 0 && o[c] < s.flatFee) throw new n({
		totalFeeWEI: s.flatFee,
		feeUnit: t(s.feeToken, i)
	});
	o[c] -= s.flatFee, r.log("amount changes after merge", { amountChanges: o });
};
//#endregion
export { i as mergeWithFeeStructure };
