import { vacationTypeResponse } from './../model/vacationType.Respond';
import { notificationTypeResponse } from './../model/notification.Respond';
import { VacationTypeRequest } from './../model/VacationTypeRequest';
import { Component, OnInit } from '@angular/core';
import { VacationRuleServiceService } from '../service/vacation-rule-service.service';
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service';
import { CommonService } from 'src/app/hmg-common/services/common/common.service';

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

  ruleTypeList: any;
  index: any;

  constructor(public vacationRuleService: VacationRuleServiceService, public ts: TranslatorService, public cs: CommonService) { }

  ngOnInit() {
    this.getVacationType();
  }

  getVacationType() {
    let request: VacationTypeRequest = new VacationTypeRequest();

    this.vacationRuleService.getVacationType(request, () => {
      this.getVacationType();
    }, this.ts.trPK('general', 'retry')).subscribe((result) => {
      if (this.cs.validResponse(result)) {
        this.ruleTypeList = result.VrItemTypesList;
        console.log(this.ruleTypeList);
      } else {
        this.cs.presentAlert(result.ErrorEndUserMessage);
      }
    });
  }

  NextPage() {
    this.cs.sharedService.setSharedData(this.ruleTypeList[this.index], vacationTypeResponse.SHARED_DATA);

    if (this.ruleTypeList[this.index].ITEM_TYPE == "*") {
      let notificatioAtt: notificationTypeResponse = new notificationTypeResponse();
      notificatioAtt.FYI_FLAG = "";
      notificatioAtt.NOTIFICATION_DISPLAY_NAME = "All";
      notificatioAtt.NOTIFICATION_NAME = "*";
      notificatioAtt.NOTIFICATION_SUBJECT = "";
      this.cs.sharedService.setSharedData(notificatioAtt, notificationTypeResponse.SHARED_DATA);
      this.cs.navigateForward('/vacation-rule/create-vacation-rule');
    } else {
      this.cs.navigateForward('/vacation-rule/notification-type');
    }


  }

}
