import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { InstructorService } from '../../../services/instructor.service';

import { InstructorData } from '../../../structures/instructor-data';

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

@Component({
  selector: 'app-edit-instructor-profile-page',
  templateUrl: './edit-instructor-profile-page.component.html',
  styleUrls: ['./edit-instructor-profile-page.component.scss']
})
export class EditInstructorProfilePageComponent implements OnInit {

  instructorData: InstructorData | null = null;

  targetAfterSubmit: string = Globals.pages.instructorProfile.path;

  constructor(private route: ActivatedRoute, private instructorService: InstructorService) { }

  ngOnInit(): void {
    var idString = this.route.snapshot.paramMap.get('id');
    if(idString != null) {
      var id = +idString;
      if(id != NaN && id != Infinity && id != -Infinity) {
        this.loadSelectedUser(id);
      }
    }
  }

  async loadSelectedUser(id: number): Promise<void> {
    var data = await this.instructorService.getInstructorById(id);
    if(data != undefined) {
      this.instructorData = data;
    } else {
      this.instructorData = null;
    }
  }

}
