import { Component, OnInit, Inject } from '@angular/core';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
import { InstructorData } from '../../../structures/instructor-data';

import { emptyInstructorDataFactory } from '../../../empty-objects/empty-instructor-data';

import * as Globals from '../../../globals';

@Component({
  selector: 'app-change-role-dialog',
  templateUrl: './change-role-dialog.component.html',
  styleUrls: ['./change-role-dialog.component.scss']
})
export class ChangeRoleDialogComponent implements OnInit {

  roles: string[] = [];
  rolesPretty: string[] = Globals.instructorRolesPretty;
  newRole: string = '';
  user: InstructorData = emptyInstructorDataFactory();

  constructor(public dialogRef: MatDialogRef<ChangeRoleDialogComponent>, 
              @Inject(MAT_DIALOG_DATA) public data: { user: InstructorData, allowedTo: string }) {
    this.newRole = data.user.role;
    this.roles = Globals.instructorRoles.slice(0, Globals.instructorRoles.indexOf(data.allowedTo));
    this.user = data.user;
  }

  ngOnInit(): void {
  }

  close(): void {
    this.dialogRef.close();
  }

}
