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

import { CourseData } from '../../../structures/course-data';
import { emptyCourseDataFactory } from '../../../empty-objects/empty-course-data';
import { CourseThemeData } from '../../../structures/course-theme-data';

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

@Component({
  selector: 'app-school-course-basic-info',
  templateUrl: './school-course-basic-info.component.html',
  styleUrls: ['./school-course-basic-info.component.scss']
})
export class SchoolCourseBasicInfoComponent implements OnInit {

  @Input() courseData: CourseData = emptyCourseDataFactory();
  
  courseThemes: CourseThemeData[] | null = null;

  constructor(private courseThemeService: CourseThemeService) {

    // nacteni temat kurzu
    this.courseThemeService.courseThemes$.subscribe((themes: CourseThemeData[] | null) => {
      this.courseThemes = themes;
    });
    this.courseThemeService.actualizeCourseThemes();
  }

  ngOnInit(): void {
  }

  getThemeNameById(id: number | null): string {
    if(this.courseThemes != null && id != null) {
      var found = this.courseThemes.find(theme => { return theme.ID == id; });
      if(found != undefined) {
        return found.name;
      }
    }
    return '';
  } 

}
