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

import { CourseService } from '../../../services/course.service';

import { CourseData } from '../../../structures/course-data';

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

@Component({
  selector: 'app-school-questionnaire-page',
  templateUrl: './school-questionnaire-page.component.html',
  styleUrls: ['./school-questionnaire-page.component.scss']
})
export class SchoolQuestionnairePageComponent implements OnInit {

  courseData: CourseData | null = null;

  courseId: number = 0;

  returnPage = Globals.pages.schoolCourses;

  constructor(private route: ActivatedRoute, private courseService: CourseService) { }

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

  async loadSelectedCourse(id: number): Promise<void> {
    var data = await this.courseService.getCourseById(id);
    this.courseData = data;
  }

}
