import { Component, OnInit } from '@angular/core';
import { _Rank, _Class, _Race, RPCPermission  } from '../../../../../../backend/Types/Types'
import { NbToastrService } from '@nebular/theme';
import { IApiService } from '../../services/ApiService/ApiService';


@Component({
  selector: 'changePermissions',
  templateUrl: './changePermissions.component.html',
})
export class ChangePermissionsComponent implements OnInit{

  permissions:RPCPermission[] = []
  ranks = _Rank

  constructor(
    private api : IApiService,
    private toastr: NbToastrService
  ){}

  async ngOnInit(){
    const modify = this.api.get('modifyPermissions')
    if(!modify) return
    this.permissions = await modify.getPermissions()
  }

  settingChanged = async (value, key, perm:RPCPermission) => {
    const modify = this.api.get('modifyPermissions')
    if(!modify) return


    perm[key] = value
    await modify.setPermission(perm).catch(e => {
      
    })
    this.toastr.success('Permission updated', 'Success')
  }
}