import { vacationTypeResponse } from './../model/vacationType.Respond';
import { VRuleItemType } from './../model/vr.itemType.List';
import { notificationTypeResponse } from './../model/notification.Respond';
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';
import { notificationTypeRequest } from '../model/notification.Request';

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

  itemTypeObj: VRuleItemType;
  itemType: string;
  notifTypeSel: any;
  notification_list: any;
  var_notification: any;


  constructor(public vacationRuleService: VacationRuleServiceService, public ts: TranslatorService, public cs: CommonService) {
    this.itemTypeObj= this.cs.sharedService.getSharedData(vacationTypeResponse.SHARED_DATA, false);
    this.itemType = this.itemTypeObj.ITEM_TYPE_DISPLAY_NAME;
  }

  ngOnInit() {
    console.log(this.cs.sharedService.getSharedData(vacationTypeResponse.SHARED_DATA, false));
    this.getNotificationType();
  }

  NextPage() {
    if (this.notifTypeSel == "*") {
      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);
    } else {
      this.cs.sharedService.setSharedData(this.notification_list[this.var_notification], notificationTypeResponse.SHARED_DATA);
    }
    this.cs.navigateForward('/vacation-rule/create-vacation-rule');
  }

  getNotificationType() {
    let request: notificationTypeRequest = new notificationTypeRequest();
    request.P_ITEM_TYPE = this.itemTypeObj.ITEM_TYPE;
    this.vacationRuleService.getNotificationType(request, () => {
      this.getNotificationType();
    }, this.ts.trPK('general', 'retry')).subscribe((result) => {
      console.log(result);
      if (this.cs.validResponse(result)) {
        console.log(result.GetItemTypeNotificationsList);
        this.notification_list = result.GetItemTypeNotificationsList;
      } else {
        this.cs.presentAlert(result.ErrorEndUserMessage);
      }
    });
  }
}
