"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPendingAmounts = exports.usePendingRedeemAmt = void 0;
var utils_1 = require("../../utils");
var common_1 = require("../common");
function usePendingRedeemAmt(vault, account) {
    var withdrawStatus = (0, common_1.useCallPoll)(3, vault === null || vault === void 0 ? void 0 : vault.getWithdrawStatus, account).res;
    var recordSharesInUnderlying = (0, common_1.useCallPoll)(3, vault === null || vault === void 0 ? void 0 : vault.sharesToUnderlying, (withdrawStatus === null || withdrawStatus === void 0 ? void 0 : withdrawStatus.shares) || 0).res;
    return getPendingAmounts(recordSharesInUnderlying, withdrawStatus);
}
exports.usePendingRedeemAmt = usePendingRedeemAmt;
function getPendingAmounts(recordSharesInUnderlying, withdrawStatus) {
    var _a;
    // Epoch-based vaults have only WithdrawRecord.shares
    // Non-epoch-based vaults have both WithdrawRecord.shares and WithdrawRecord.value
    // .value is value of shares when u withdraw, but it’s checked against actual value of shares after a harvest is done.
    // So to get accurate value of shares, we can do MIN(sharesToUnderlying(WithdrawRecord.shares), WithdrawRecord.value)
    var withdrawRecordShares = withdrawStatus === null || withdrawStatus === void 0 ? void 0 : withdrawStatus.shares;
    /* @ts-ignore-next-line */
    var withdrawRecordValue = withdrawStatus === null || withdrawStatus === void 0 ? void 0 : withdrawStatus.value;
    var pendingUnderlyingBN = 
    /* @ts-ignore-next-line */
    withdrawRecordValue == null
        ? recordSharesInUnderlying
        : // Take min of WithdrawRecord.shares and sharesToUnderlying(WithdrawRecord.value)
            ((_a = (0, utils_1.toBN)(withdrawRecordValue || 0)) === null || _a === void 0 ? void 0 : _a.lt(recordSharesInUnderlying || 0))
                ? withdrawRecordValue
                : recordSharesInUnderlying;
    var pendingSharesBN = withdrawRecordShares && (0, utils_1.toBN)(withdrawRecordShares);
    return { pendingUnderlyingBN: pendingUnderlyingBN, pendingSharesBN: pendingSharesBN };
}
exports.getPendingAmounts = getPendingAmounts;
//# sourceMappingURL=usePendingRedeemAmt.js.map