import { Component, OnInit } from '@angular/core';
import { XpoDialogRef } from '@xpo/common';
import { Role, RoleService } from '../../shared';

@Component({
    selector: 'app-delete-role',
    templateUrl: './delete-role-confirmation.component.html',
    styleUrls: [ './delete-role-confirmation.component.scss' ]
})
export class DeleteRoleConfirmationComponent implements OnInit {
    public role: Role = undefined;

    constructor(private roleService: RoleService, public dialogRef: XpoDialogRef<DeleteRoleConfirmationComponent>) {
        this.role = this.dialogRef._containerInstance._config.data;
    }

    ngOnInit() {
    }

    deleteRole() {
        if (this.role != undefined && this.role.name) {
            this.roleService.deleteRole(this.role);
        }
        this.dialogRef.close('canceled');
    }

    onClose() {
        this.dialogRef.close('canceled');
    }
}
