import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { concatMap, tap } from 'rxjs/operators';
import { RuStudentRegistersService } from 'src/app/core/service/ru-student/ru-student-registers.service';
import { StudentService } from 'src/app/core/service/student/student.service';
import { TestingInformationService } from 'src/app/core/service/testing-information/testing-information.service';
import { TestingInfoContainer } from '../testing-info/testing-info.container';

@Component({
    selector: 'app-upload-student',
    templateUrl: './upload-student.container.html',
    styleUrls: ['./upload-student.container.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class UploadStudentContainer implements OnInit {
    studentList$ = new Observable()
    testing$ = new Observable()
    testingInfomationData;
    constructor(
        private studentSV: StudentService,
        private activeRoute: ActivatedRoute,
        private testingInfomationSV: TestingInformationService,
        private studentRuSV: RuStudentRegistersService
    ) { }

    ngOnInit(): void {
        this.testing$ = this.activeRoute.params.pipe(
            concatMap(x => this.testingInfomationSV.get(x.id)),
            tap(x => this.testingInfomationData = x)
        )
    }

    search(query){
        if(query) this.studentList$ = this.studentSV.search('?'+query)
    }

    searchRu(query){
        if(query) this.studentList$ = this.studentRuSV.search('?'+query)
    }


}
