import { Component, ChangeDetectorRef, ChangeDetectionStrategy, Input } from '@angular/core'

import { Role } from './models'
import { AdminManageAccessDataService } from './access-data.service'

@Component({
    selector: 'gisaf-admin-role',
    templateUrl: './role.component.html',
    styleUrls: ['./role.component.css'],
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AdminRoleComponent {
    @Input() role: Role

    constructor(
        private cdr: ChangeDetectorRef,
        public adminManageAccessDataService: AdminManageAccessDataService,
    ) {}

    delete() {
        this.adminManageAccessDataService.deleteRole(this.role).subscribe(
            res => {
                this.adminManageAccessDataService.init()
            }
        )
    }

    edit() {
        this.adminManageAccessDataService.openRoleDialog(this.role)
    }
}