import {Injectable} from '@angular/core';

@Injectable()
export class Load {
    constructor() {
    }

    private isLoad = false;
    private time = 0;
    private _nFlag = false;

    toLoad(msg, type) {
        this.isLoad = true;
        document.getElementById('v-loading').style.display = 'block';
        document.getElementById('loading-inner').innerText = msg;
        if (!this._nFlag && type) {
            this.time = 0;
            // @ts-ignore
            document.getElementsByClassName('circle_process')[0].style.display = 'block';
            document.getElementById('innerNum').innerText = this.time.toString() + 's';
            this.addNum();
            this._nFlag = true;
        }
    }

    addNum() {
        setTimeout(() => {
            if (this.isLoad) {
                this.time ++;
                document.getElementById('innerNum').innerText = this.time.toString() + 's';
                this.addNum();
            }
        }, 1000);
    }

    offLoad() {
        this.isLoad = false;
        if (this._nFlag) {
            this._nFlag = false;
            // @ts-ignore
            document.getElementsByClassName('circle_process')[0].style.display = 'none';
            document.getElementById('innerNum').style.display = 'none';
        }
        document.getElementById('v-loading').style.display = 'none';
        document.getElementById('loading-inner').innerText = '';
        document.getElementById('innerNum').innerText = '0s';
    }
}
