"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMaxDeposit = void 0;
var utils_1 = require("../../utils");
var react_1 = require("react");
var useMaxDeposit = function (tvl, maxTvl, accountBalance) {
    return (0, react_1.useMemo)(function () {
        var _a;
        // Need to do 99% of maxTvl to prevent odd contract errors.
        var nearMax = (_a = maxTvl === null || maxTvl === void 0 ? void 0 : maxTvl.mul(99)) === null || _a === void 0 ? void 0 : _a.div(100);
        var valuesArentDefault = maxTvl && tvl && !((maxTvl === null || maxTvl === void 0 ? void 0 : maxTvl.isZero()) && (tvl === null || tvl === void 0 ? void 0 : tvl.isZero()));
        var spaceLeftBN = nearMax === null || nearMax === void 0 ? void 0 : nearMax.sub(tvl);
        var isFull = valuesArentDefault ? spaceLeftBN === null || spaceLeftBN === void 0 ? void 0 : spaceLeftBN.lte(0) : false;
        var maxAccountBalance = accountBalance;
        var maxBN = isFull
            ? (0, utils_1.toBN)(0)
            : (spaceLeftBN === null || spaceLeftBN === void 0 ? void 0 : spaceLeftBN.gt(maxAccountBalance))
                ? maxAccountBalance
                : spaceLeftBN;
        return { maxBN: maxBN, isFull: isFull };
    }, [maxTvl, tvl, accountBalance]);
};
exports.useMaxDeposit = useMaxDeposit;
//# sourceMappingURL=useMaxDeposit.js.map