import { Component, OnInit } from '@angular/core';
import { NavController } from '@ionic/angular';
import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service';
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
import { DomSanitizer } from '@angular/platform-browser';
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss'],
})
export class HomeComponent implements OnInit {
  isSkip: boolean = false;
  setTime: number = 5;
  advertisement: any;
  data: any;
  constructor(public nav: NavController, public cs: CommonService, public sanitizer: DomSanitizer, public authService: AuthenticationService, public ts: TranslatorService) { }

  ngOnInit() {
    this.data = this.cs.sharedService.getSharedData(
      AuthenticationService.ADS_DATA,
      false
    );
    this.advertisement = this.data.result.data.advertisement.viewAttachFileColl[0];
    this.setTime = this.data.result.data.advertisement.durationInSeconds;
    this.setTimer();
  }
  skip() {
    this.nav.pop();
    CommonService.SKIP = true;
  }
  setTimer() {
    setTimeout(() => {
      this.setTime--;
      if (this.setTime == 0) {
        this.isSkip = true;
      } else {
        this.setTimer();
      }
    }, 1000);
  }
  setView(status) {
    // var request =
    // {
    //   "ItgSurveyId": data.serviceId, "ItgNotificationMasterId": data.notificationMasterId, "ItgComments": this.note, "ItgQuestionResponses": [
    //     { "questionId": 1, "optionId": null, "starRating": parseInt(this.rate) },
    //     { "questionId": 2, "optionId": 4, "starRating": parseInt(this.satisfied) }
    //   ]
    // };



    this.authService.setViewAds({
      "ItgNotificationMasterId": this.data.result.data.notificationMasterId,
      "ItgAdvertisement": {
        "advertisementId": this.data.result.data.advertisementId,
        "acknowledgment": status
      }
    }, (

    ) => { }, this.ts.trPK('general', 'ok')).subscribe((result) => {
      CommonService.SKIP = true;
      this.cs.openHome();
    })
  }

}
