import { __awaiter, __generator } from "tslib";
import { useState } from 'react';
import { useEffectAsync } from '../../react-hooks';
import { DURATION_HIDE_ANIMATION } from './constants';
var wait = function (duration) {
    if (duration === void 0) { duration = 100; }
    return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
        return [2 /*return*/, new Promise(function (resolve) { return setTimeout(resolve, duration); })];
    }); });
};
export function useMinimalWait(_a) {
    var _this = this;
    var visible = _a.visible, minWait = _a.minWait;
    var _b = useState(false), isMinimalWaitReached = _b[0], setIsMinimalWaitReached = _b[1];
    useEffectAsync(function () { return __awaiter(_this, void 0, void 0, function () {
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, wait(minWait)];
                case 1:
                    _a.sent();
                    setIsMinimalWaitReached(true);
                    return [2 /*return*/];
            }
        });
    }); }, [visible]);
    return isMinimalWaitReached;
}
export function useHidden(_a) {
    var _this = this;
    var visible = _a.visible, isMinimalWaitReached = _a.isMinimalWaitReached;
    var _b = useState(false), isHidden = _b[0], setIsHidden = _b[1];
    useEffectAsync(function () { return __awaiter(_this, void 0, void 0, function () {
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    if (visible || !isMinimalWaitReached) {
                        return [2 /*return*/];
                    }
                    return [4 /*yield*/, wait(DURATION_HIDE_ANIMATION)];
                case 1:
                    _a.sent();
                    setIsHidden(true);
                    return [2 /*return*/];
            }
        });
    }); }, [visible, isMinimalWaitReached]);
    return isHidden;
}
//# sourceMappingURL=hooks.js.map