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

let ConfirmDeletionCtrlInject = ['$uibModalInstance', 'data', 'config'];
export class DialogsConfirmDeletionCtrl {
    static get $inject(){
        return ConfirmDeletionCtrlInject;
    }
    constructor(...injectables){
        Util.injectNg(injectables, ConfirmDeletionCtrlInject, this);
    }
    remove(row){
        Util.removeFromArray(this.data, '$$hashKey', row.$$hashKey);
        if (Util.isEmpty(this.data)) this.$uibModalInstance.dismiss('no-data');
    }
    _get(row, value){
        return getSafe(row, value);
    }
    get hasRemovables(){
        return this.data.some(o => !o.notRemovable) && !this.config.loading;
    }
    no(){
        this.$uibModalInstance.dismiss('no');
    }
    yes(){
        this.$uibModalInstance.close(this.data.filter(o => !o.notRemovable));
    }
}