import { Component, OnInit } from '@angular/core';
import * as moment from 'moment';
import { HyperService } from '../../core/services/http.service';
import { Router } from "@angular/router";
import { LocalStorage } from '../../core/services/local_storage.service';

@Component({
  selector: 'app-feedback',
  templateUrl: './feedback.component.html',
  styleUrls: ['./feedback.component.scss']
})
export class FeedbackComponent implements OnInit {
  sales_date: any;
  user_dashboard: any;
  loader: boolean;
  percentage: any;
  survey_list: any;
  user_role:any;
  constructor(private server: HyperService, private router: Router) {
    if (LocalStorage.getValue('user_data') != undefined){
        this.user_role = LocalStorage.getValue('user_data').role;
    }
  }

  ngOnInit() {
      this.getFeedback(); 
  }
 
   
  getFeedback() {
      this.loader = true
      this.server.get("survey")
          .then((data) => {
              if (data.status == 200 && data.result.response != 'failed') {
                  this.survey_list = data.result.data;
                  this.loader = false
              } else if(data.status==406){
                  this.loader = false
              }else if (data.result.status == 401 && data.result.response == 'failed') {}
          });
  }
 

  onSelect(list, index) {
    console.log(list,index,this.survey_list)
      if (list.status == 1 || list.status == 3 || list.status == 7) {
          LocalStorage.setValue('current_feedback', list)
          LocalStorage.setValue('feedback_is_attened', this.survey_list[index].is_attended)
          this.router.navigateByUrl('feedback/' + list.assessmentid);
      } else {
          alert('Expired')
      }

  }

}