import { MLoadingStates } from './loading-states';
export var DEFAULT_INVISBLE_THRESHOLD_IN_MILISECONDS = 300;
export var DEFAULT_VISIBLE_THRESHOLD_IN_MILISECONDS = 1000;
export var INTERVAL_STEP_IN_MILLISECONDS = 100;
var LoadingScheduler = /** @class */ (function () {
    function LoadingScheduler(_stateTransitionCb, _invisibleThresholdInMiliseconds, _visibleThresholdInMiliseconds) {
        if (_invisibleThresholdInMiliseconds === void 0) { _invisibleThresholdInMiliseconds = DEFAULT_INVISBLE_THRESHOLD_IN_MILISECONDS; }
        if (_visibleThresholdInMiliseconds === void 0) { _visibleThresholdInMiliseconds = DEFAULT_VISIBLE_THRESHOLD_IN_MILISECONDS; }
        this._stateTransitionCb = _stateTransitionCb;
        this._invisibleThresholdInMiliseconds = _invisibleThresholdInMiliseconds;
        this._visibleThresholdInMiliseconds = _visibleThresholdInMiliseconds;
        this._loadingTimeInMilliseconds = 0;
    }
    LoadingScheduler.prototype.start = function () {
        var _this = this;
        this._stateTransitionCb(MLoadingStates.ActiveInvisible);
        this._interval = window.setInterval(function () {
            _this._loadingTimeInMilliseconds += INTERVAL_STEP_IN_MILLISECONDS;
            if (_this._loadingTimeInMilliseconds >= _this._invisibleThresholdInMiliseconds) {
                _this._stateTransitionCb(MLoadingStates.ActiveVisible);
            }
        }, INTERVAL_STEP_IN_MILLISECONDS);
    };
    LoadingScheduler.prototype.stop = function () {
        var _this = this;
        if (this._loadingTimeInMilliseconds < this._invisibleThresholdInMiliseconds
            ||
                (this._loadingTimeInMilliseconds
                    >
                        (this._invisibleThresholdInMiliseconds + this._visibleThresholdInMiliseconds))) {
            this._stateTransitionCb(MLoadingStates.Inactive);
        }
        else {
            window.setTimeout(function () { return _this._stateTransitionCb(MLoadingStates.Inactive); }, (this._invisibleThresholdInMiliseconds + this._visibleThresholdInMiliseconds)
                -
                    this._loadingTimeInMilliseconds);
        }
        clearInterval(this._interval);
    };
    return LoadingScheduler;
}());
export default LoadingScheduler;
//# sourceMappingURL=loading-scheduler.js.map