import { Util } from '../util/Util';

let WaitCtrlInject = ['$uibModalInstance', '$timeout', 'texts', 'classes', 'progressInfo'];
export class DialogsWaitCtrl {
    static get $inject(){
        return WaitCtrlInject;
    }
    constructor(...injectables){
        Util.injectNg(injectables, WaitCtrlInject, this)
    }
    close(){
        this.$uibModalInstance.close();
    }
    get getProgress(){
        let progress = this.progressInfo.progress / this.progressInfo.total * 100;
        if (progress === this.progressInfo.total) this.$timeout(() => this.close(), 250);
        return {
            width: `${progress}%`
        }
    }
    $onInit(){
        this.msg = this.texts.msg;
        let { total, progress } = this.progressInfo;
        this.progressInfo.total = angular.isDefined(total) ? total : 200;
        this.progressInfo.progress = angular.isDefined(progress) ? progress : 0;
        let { icon } = this.classes;
        this.classes.icon = angular.isDefined(icon) && angular.isString(icon) ? icon : 'fas fa-clock';
        this.header = Util.setTranslation(this.texts.header);
    }
}