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

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

    private isLoad = false;
    private time = 0;

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

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

    offLoad() {
        this.isLoad = false;
        document.getElementById('v-loading').style.display = 'none';
        document.getElementById('loading-inner').innerText = '';
        document.getElementById('innerNum').innerText = '0s';
    }
}
