import { WorklistsubmitterInfoResponse } from './../models/WorklistsubmitterInfoRes';
import { WorklistMainService } from './../service/work-list.main.service';
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
import { WorkListSubmitterInfoRequest } from './../models/WorklistsubmitterInfoReq';
import { Component, OnInit } from '@angular/core';
import { EITNotificatonBodyResponse } from 'src/app/eit/models/EITNotificationBodyRes';
import { AbsenceNotificatonBodyResponse } from '../models/AbsenceNotificationBodyRes';

@Component({
  selector: 'app-work-list-details',
  templateUrl: './work-list-details.component.html',
  styleUrls: ['./work-list-details.component.scss'],
})
export class WorkListDetailsComponent implements OnInit {
  submitterInfoRes: any;
  notificationBodyRes: any;
  notBodyType: string = "";
  notBodyResult: any;
  getPassNotificationDetails: any;
  private WorkListSubmitterInfoObj: WorkListSubmitterInfoRequest;

  constructor(public cs: CommonService, public worklistMainService: WorklistMainService) {
    this.WorkListSubmitterInfoObj = new WorkListSubmitterInfoRequest();
    this.notBodyType = this.cs.sharedService.getSharedData('NotBodyType', false);
    if (this.notBodyType == "EIT") {
      this.notBodyResult = this.cs.sharedService.getSharedData(EITNotificatonBodyResponse.SHARED_DATA, false);
      this.getPassNotificationDetails = this.cs.sharedService.getSharedData(EITNotificatonBodyResponse.NOT_WORKLIST, false);
    } else if (this.notBodyType == "ABSENCE") {
      this.notBodyResult = this.cs.sharedService.getSharedData(AbsenceNotificatonBodyResponse.SHARED_DATA, false);
      this.getPassNotificationDetails = this.cs.sharedService.getSharedData(AbsenceNotificatonBodyResponse.NOT_WORKLIST, false);
    }
  }

  ngOnInit() {
    this.WorkListSubmitterInfoObj.P_PAGE_LIMIT = 100;
    this.WorkListSubmitterInfoObj.P_PAGE_NUM = 1;
    this.WorkListSubmitterInfoObj.P_SELECTED_EMPLOYEE_NUMBER = this.getPassNotificationDetails.SELECTED_EMPLOYEE_NUMBER;
    this.WorkListSubmitterInfoObj.P_SELECTED_RESP_ID = -999;
    this.WorkListSubmitterInfoObj.P_SEARCH_EMAIL_ADDRESS = "";
    this.WorkListSubmitterInfoObj.P_SEARCH_EMPLOYEE_DISPLAY_NAME = "";
    this.WorkListSubmitterInfoObj.P_SEARCH_USER_NAME = "";

    this.getsubmitterInfo(this.WorkListSubmitterInfoObj);
    this.handleNotificationBody();
  }

  getsubmitterInfo(notificationSubmitterInfoObj) {
    this.worklistMainService.getSubmitterInfo(notificationSubmitterInfoObj).
      subscribe((result: WorklistsubmitterInfoResponse) => {
        this.handleSubmitterInfoResult(result);
      });
  }
  handleSubmitterInfoResult(result) {
    if (this.cs.validResponse(result)) {
      // this.sharedData.setSharedData(result, WorKListResponse.SHARED_DATA);
      if (this.cs.hasData(result.MemberInformationList)) {
        //if (result.MemberInformationList != null) {
        this.submitterInfoRes = result.MemberInformationList;
      } // if result == null
    } // valid it
  }// End handleWorkListButtonsResult
  handleNotificationBody() {
    this.notificationBodyRes = {};
    if (this.cs.hasData(this.notBodyResult)) {
      this.notificationBodyRes = this.notBodyResult;
    }
  }

}
