import {Loading} from 'view-design'
let needLoadingRequestCount = 0;
function startLoading () {
    Loading.start();
}

function endLoading() {
    Loading.finish();
}

const tryCloseLoading = () => {
    if (needLoadingRequestCount === 0) {
        endLoading();
    }
};

export function showFullScreenLoading () {
    if (needLoadingRequestCount === 0) {
        startLoading();
    }
    needLoadingRequestCount++;
}

export function tryHideFullScreenLoading () {
    if (needLoadingRequestCount <= 0) return;
    needLoadingRequestCount--;
    if (needLoadingRequestCount === 0) {
        tryCloseLoading()
    }
}
