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

import { CourseThemeService } from '../../../services/course-theme.service';

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

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

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

  themeData: CourseThemeData | null = null;

  themeId: number = 0;

  returnPage = Globals.pages.allThemes;

  constructor(private route: ActivatedRoute, private courseThemeService: CourseThemeService) { }

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

  async loadSelectedTheme(id: number): Promise<void> {
    var data = await this.courseThemeService.getThemeById(id);
    this.themeData = data;
  }

}
