import { Component, OnInit } from '@angular/core';
import { HyperService } from '../../core/services/http.service';

@Component({
  selector: 'app-addparticipantpop',
  templateUrl: './addparticipantpop.component.html',
  styleUrls: ['./addparticipantpop.component.scss']
})
export class AddparticipantpopComponent implements OnInit {
  screen_callback:any;
  is_modal_visible: boolean = false;
  schedule_id:any;
  formData: any = [];
  participant_list: any = [];
  selected_participant:any = [];
  addparticipant_error:any;

  constructor(private server: HyperService) { }

  ngOnInit() {
  }
  public showAddParticipant(sch_id: string = "", callBack: any = null){
    this.schedule_id = sch_id;
    this.screen_callback = callBack;
    this.is_modal_visible = true;
  }
  onCloseModal(){
    this.is_modal_visible = false;
    this.screen_callback(true);
  }
  validParticipant() {
    // this.participant_list = [];
    // this.mymodel = searchValue;

    this.server.post("trainer/smpinparticipant", {
      schedule_id:this.schedule_id,
      smpin:this.formData.participantsmpin
    }).then((data) => {
      if (data.status == 200 && data.result.response == "success") {
        // if(data.result.data.length>0){
        //   this.itemdetail = data.result.data;
        // }else{
        //   this.trainer_welcomenote = 'Training is not available';
        // }
      } else if (data.result.response == "failed") {
          this.addparticipant_error = data.result.message;
      }
    })

  }
  participantSelected(item){
    let isavail = this.selected_participant.indexOf(item);
    if(isavail!=-1){
      this.selected_participant.splice(isavail, 1);
    }else{
      this.selected_participant.push(item);
    }
  }
  onSubmit(){
    this.is_modal_visible = false;
    this.screen_callback(true);
  }
}
