import {Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef} from '@angular/core';
import {Observable} from 'rxjs';
import {Router} from '@angular/router';
import {TestingInformationService} from '../../../../../core/service/testing-information/testing-information.service';
import {SweetalertService} from '../../../../../core/service/sweetalert/sweetalert';
import {MatDialog} from '@angular/material/dialog';
import {
  DialogChangeSeatComponent
} from '../../../../candidate-list/candidate-list/presenter/dialog/dialog-change-seat/dialog-change-seat.component';
import {tap} from 'rxjs/operators';
import {
  DialogExtendInformationDateFormComponent
} from '../../presenter/form/dialog-extend-information-date-form/dialog-extend-information-date-form.component';

@Component({
  selector: 'app-extend-information-date',
  templateUrl: './extend-information-date.container.html',
  styleUrls: ['./extend-information-date.container.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ExtendInformationDateContainer implements OnInit {

  subjectList$ = new Observable();

  constructor(
    private router: Router,
    private TestinforSV: TestingInformationService,
    private cdr: ChangeDetectorRef,
    private swSV: SweetalertService,
    private dialog: MatDialog,
  ) { }

  ngOnInit(): void {
    this.subjectList$ = this.TestinforSV.getAll();
  }

  search(query){
    if(query) return this.subjectList$ = this.TestinforSV.search(`?${query}`);
    if(!query) return this.subjectList$ = this.TestinforSV.getAll();
  }

  edit(id){
    this.router.navigate(['extend-information-date/edit', id]);
  }

  openDialog(id){
    const dialogRef = this.dialog.open(DialogExtendInformationDateFormComponent, {
      width: '500px',
      height: '300px',
      data: {
        id,
        state : 'edit',
      }
    });
    dialogRef.afterClosed().pipe(
      tap(x => {
        console.log(x)
      })
    ).subscribe();
  }

  // edit(id){
  //   this.router.navigate(['extend-information-date/edit', id]);
  // }

}
