import { Component, OnInit } from '@angular/core';
import { HyperService } from '../../core/services/http.service';
import { DomSanitizer, SafeResourceUrl, SafeUrl } from '@angular/platform-browser';

@Component({
  selector: 'app-feedback-popup',
  templateUrl: './feedback-popup.component.html',
  styleUrls: ['./feedback-popup.component.scss']
})
export class FeedbackPopupComponent implements OnInit {

  is_modal_visible: boolean = false;
  screen_callback: any;
  assessment_id: number;
  content_data: any;
  questionsList:any;
  page_load: boolean;
  excel_load: boolean;
  export_url: any;

  constructor(private server: HyperService, private sanitizer: DomSanitizer) { }

  ngOnInit() {
  } 

  public showcontentrModal(url: string = "", data: any = {}, callBack: any = null) {
    console.log("here")
    this.is_modal_visible = true;
    this.content_data = data.sendData;
    console.log('Data', this.content_data)
    this.screen_callback = callBack;
    this.getDseReportDetails()

  }


  getDseReportDetails() {
    this.page_load = true;
    this.server.get('manager/surveyuserreport/'+this.content_data.assessmentid+'/'+this.content_data.userid)
      .then((data) => {
        if (data.status == 200 && data.result.response != 'failed') {
          this.questionsList = data.result.data;
          this.page_load = false;
          console.log('questionsList', this.questionsList)
        } else if (data.result.status == 401 && data.result.response == 'failed') { 
        }
      });
  }

  onCloseModal(){
    this.is_modal_visible = false;
    this.screen_callback(true);
  }
  
  clickExcelDownload(list) {
    this.page_load = true;
    this.excel_load = true;
    this.server.get("managerexport/surveyuserreportexport/"+this.content_data.assessmentid+'/'+this.content_data.userid).then((data) => {
        if (data.status == 200) {
            this.page_load = false;
            this.export_url = (data.result.data);
            setTimeout(() => this.export_url = "", 1000);
            this.excelExport();
        } else {
            // alert("error");
        }
    });
}

excelExport() {
    return this.sanitizer.bypassSecurityTrustResourceUrl(this.export_url);

}
}
