"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMaxDeposit = exports.useIsFullEnough = void 0;
var utils_1 = require("../../utils");
var react_1 = require("react");
function useIsFullEnough(tvl, maxTvl) {
    return (0, react_1.useMemo)(function () {
        if (tvl == null)
            return false;
        if (maxTvl == null)
            return false;
        var nearMax = maxTvl === null || maxTvl === void 0 ? void 0 : maxTvl.sub(1000);
        var valuesArentDefault = tvl === null || tvl === void 0 ? void 0 : tvl.gt(0);
        var spaceLeft = nearMax === null || nearMax === void 0 ? void 0 : nearMax.sub(tvl);
        var isFull = valuesArentDefault ? spaceLeft === null || spaceLeft === void 0 ? void 0 : spaceLeft.lte(0) : false;
        return isFull;
    }, [tvl, maxTvl]);
}
exports.useIsFullEnough = useIsFullEnough;
var useMaxDeposit = function (tvl, maxTvl, accountBalance) {
    return (0, react_1.useMemo)(function () {
        // Need to do 99% of maxTvl to prevent odd contract errors.
        var nearMax = maxTvl === null || maxTvl === void 0 ? void 0 : maxTvl.sub(1000);
        var valuesArentDefault = maxTvl && tvl && !(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