import { getMainAccount } from "../../account";
import { getAlpacaApi } from "./alpaca";
import { createTransaction } from "./createTransaction";
import { transactionToIntent } from "./utils";
import BigNumber from "bignumber.js";
export function genericEstimateMaxSpendable(network, kind) {
    return async ({ account, parentAccount, transaction }) => {
        const mainAccount = getMainAccount(account, parentAccount);
        const draftTransaction = {
            ...createTransaction(account),
            ...transaction,
            amount: mainAccount.spendableBalance,
        };
        const fees = await getAlpacaApi(network, kind).estimateFees(transactionToIntent(mainAccount, draftTransaction));
        const bnFee = BigNumber(fees.value.toString());
        return BigNumber.max(0, account.spendableBalance.minus(bnFee));
    };
}
//# sourceMappingURL=estimateMaxSpendable.js.map