import { Component, OnInit, ElementRef, ViewChild } from "@angular/core";
import { CommonService } from "src/app/hmg-common/services/common/common.service";
import { TranslatorService } from "src/app/hmg-common/services/translator/translator.service";
import { WorkListBodyRequest } from "../models/NotificationBodyReq";
import { EITNotificatonBodyResponse } from "../models/EITNotificationBodyRes";
import { AbsenceNotificatonBodyResponse } from "../models/AbsenceNotificationBodyRes";
import { NotificatonButtonResponse } from "../models/NotificationButtonRes";
import { WorkListActionRequest } from "../models/NotificationActionReq";
import { WorkListButtonRequest } from "../models/NotificationButtonReq";
import { MenuResponse } from "src/app/hmg-common/services/menu/models/menu-response";
import { WorklistMainService } from "../service/work-list.main.service";
import { HomeComponent } from "src/app/notification/home/home.component";
import { TextInput } from 'src/app/uI-elements/text.input';
import { TextAreaInput } from 'src/app/uI-elements/text-area.input';
import { MenuService } from 'src/app/hmg-common/services/menu/menuservice.service';
import { Events, ModalController } from '@ionic/angular';
import { PONotificatonBodyResponse } from '../models/PONotificationBodyRes';
import { MONotificatonBodyResponse } from '../models/MONotificationBodyRes';
import { PRNotificatonBodyResponse } from '../models/PRNotificationBodyRes';
import { NotificationGetAttachResponse } from 'src/app/eit/models/NotificationGetAttachRes';
import { WorklistAttachService } from 'src/app/absence/service/work-list-attach.service';
import { WorkListActionHistoryRequest } from '../models/ActionHistoryReq';
import { WorkListActionHistoryResponse } from '../models/ActionHistoryRes';
import { WorklistService } from '../service/worklist.service';
import { MoreActionModalComponent } from '../more-action-modal/more-action-modal.component';
import { WorkListAttachViewComponent } from '../work-list-attach-view/work-list-attach-view.component';
import { GetSubordinatesLeavesRequest } from '../../hmg-common/services/dashbored/models/GetSubordinatesLeavesRequest';
import { DashboredService } from '../../hmg-common/services/dashbored/dashbored.service'
import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service';
import { AuthenticatedUser } from 'src/app/hmg-common/services/authentication/models/authenticated-user';
import { WorklistsubmitterInfoResponse } from '../models/WorklistsubmitterInfoRes';
import { WorkListSubmitterInfoRequest } from '../models/WorklistsubmitterInfoReq';
import { WorkListReplacementRollComponent } from '../work-list-replacement-roll/work-list-replacement-roll.component';
import { WorkListRfcComponent } from '../work-list-rfc/work-list-rfc.component';
import { ApplyActionModalComponent } from '../apply-action-modal/apply-action-modal.component';
import { GetOpenNotificationsResponse } from 'src/app/hmg-common/services/dashbored/models/GetOpenNotificationsResponse';
import { IonSlides } from '@ionic/angular';
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: "app-worklist-main",
  templateUrl: "./worklist-main.component.html",
  styleUrls: ["./worklist-main.component.scss"]
})
export class WorklistMainComponent implements OnInit {
  @ViewChild('slides') slides: IonSlides;
  private WorkListBodyObj: WorkListBodyRequest;
  private WorkListButtonsObj: WorkListButtonRequest;
  private WorkListActionObj: WorkListActionRequest;
  public static PASS_NOTIFICATION_INFO = "passNotificationInfo";
  public static PASS_ACTION_MODE = "passActionMode";
  getPassNotificationDetails: any;
  public static PASS_RES_ATTR = "passResAttr";
  TransactionID: number = -999;
  notificationBodyRes: any = [];
  stampNsNotificationBodyRes: any = [];
  stampMsNotificationBodyRes: any = [];
  actionHistoryRes: any = [];
  notificationButtonRes: any;
  actionMode: any;
  pInformation: string = "";
  pQuestion: string = "";
  RespondAttributesListRes: any;
  schemaNotific: any;
  NotRespondAttributeList: any;
  Resp2_val: any;
  notExampleJsonObject: any;
  hideForwordEmployee: any;
  exampleJsonObject: any;
  dataOfAttr: any;
  P_RESPOND_ATTRIBUTES_TBL: any;
  selEmployeeID: any;
  actionType: string = "";
  notificationArray: any = [];
  notificationDynamicAttributeArr: any;
  private textInput: TextInput;
  private textArea: TextAreaInput;
  private WorkListAttachObj: WorkListButtonRequest;
  P_PAGE_NUM: number = 1;
  P_PAGE_LIMIT: number = 100;
  notificationCount: any;
  activeSegment: any = 'info';
  lines_note_limit: any = 19;
  attachmentRes: any = [];
  private WorkListActionHistoryObj: WorkListActionHistoryRequest;
  IsReachEnd: boolean = true;
  notiActionBtnMore: any = [];
  messageSuccess: boolean = false;
  confirmMsg: string;
  newArr: any = [];
  selEmp: any;
  subordinatesleaveList: any = [];
  allSubordinatesleaveList: any = [];
  private WorkListSubmitterInfoObj: WorkListSubmitterInfoRequest;
  submitterInfoRes: any;
  approveDis: boolean = false;
  rejectDis: boolean = false;
  requestDis: boolean = false;
  moreDisabled: boolean = true;
  dirfromNotificationPage: boolean = false;
  direction: string;
  defaultSegment = '';
  public isPostNoLoad = true;
  public worklistNotifications: any;
  public totalRequestCount = 0;
  approve_label: any = "";
  reject_label: any = "";
  reqInfo_label: any = "";
  close_label: any;
  closeDis: boolean = false;
  public selectedFilter: string;
  public arr_hr_req_only = [];
  public showInformation = true;


  constructor(
    public worklistService: WorklistService,
    public common: CommonService,
    public ts: TranslatorService,
    public worklistMainService: WorklistMainService,
    public elementRef: ElementRef,
    public menuService: MenuService,
    public events: Events,
    public worklistAttachService: WorklistAttachService,
    private modalCtrl: ModalController,
    public dashboredService: DashboredService,
    public authService: AuthenticationService,
    public route: ActivatedRoute
  ) {
    this.direction = TranslatorService.getCurrentLanguageName()
    this.WorkListActionHistoryObj = new WorkListActionHistoryRequest();
    this.WorkListActionHistoryObj.P_PAGE_NUM = 1;
    this.WorkListActionHistoryObj.P_PAGE_LIMIT = this.P_PAGE_LIMIT;

    this.route.params.subscribe(val => {
      setTimeout(() => {
        this.ionAlwaysEnter();
      }, 100);
    });

  }

  ngOnInit() { }

  ionAlwaysEnter() {
    this.selEmp = this.common.sharedService.getSharedData(
      MenuResponse.SHARED_SEL_EMP,
      false
    );
    this.selectedFilter = this.common.sharedService.getSharedData('selectedFilter', false);
    console.log(this.selectedFilter);
    if (this.selEmp) { } else {
      this.authService.loadAuthenticatedUser().subscribe((user: AuthenticatedUser) => {
        if (user) {
          this.selEmp = user.ASSIGNMENT_NUMBER;
        }
      });
    }
    this.intializeNotificationDetail();
  }

  // ionViewWillEnter(){
  //   this.intializeNotificationDetail();
  // }

  public segmentChanged(event: any) {
    this.activeSegment = event.detail.value;
    if (this.activeSegment === 'info') {
      this.slides.slideTo(0);
    }
    else if (this.activeSegment === 'item-req') {
      this.slides.slideTo(1);
    }
    else if (this.activeSegment === 'action-history') {
      this.slides.slideTo(2);
    }
    else if (this.activeSegment === 'attach') {
      this.slides.slideTo(3);
    }
    console.log(" event.detail.value: " + event.detail.value);
  }

  public slideChanged(event: any) {
    this.slides.getActiveIndex().then(index => {
      console.log(index);
      console.log(event);
      if (index === 0) {
        this.activeSegment = 'info';
      }
      else if (index === 1) {
        this.activeSegment = 'item-req';
      }
      else if (index === 2) {
        this.activeSegment = 'action-history';
      }
      else if (index === 3) {
        this.activeSegment = 'attach';
      }
      console.log(this.activeSegment);
    });
  }

  public intializeNotificationDetail() {
    this.approveDis = false;
    this.rejectDis = false;
    this.requestDis = false;
    this.moreDisabled = true;
    this.closeDis = false;

    if (this.messageSuccess) {
      document.getElementById("notificationDynamicFields").innerHTML = "";
    }

    this.getPassNotificationDetails = this.common.sharedService.getSharedData(
      HomeComponent.NOTIFICATION_DATA,
      false
    );
    console.log('/////////////////////////////////////');
    console.log(this.getPassNotificationDetails);

    this.notificationArray = []
    this.subordinatesleaveList = [];
    this.notificationArray = this.common.sharedService.getSharedData(
      HomeComponent.NOTIFICATION_ARR,
      false
    );
    console.log(this.selectedFilter);
    if (this.selectedFilter === 'HRSSA' || this.selectedFilter === 'STAMP') {
      console.log("ENAD")
      this.arr_hr_req_only = [];
      this.sortRequests();
    }
    this.WorkListBodyObj = new WorkListBodyRequest();
    this.WorkListButtonsObj = new WorkListButtonRequest();
    this.WorkListAttachObj = new WorkListButtonRequest();
    this.WorkListSubmitterInfoObj = new WorkListSubmitterInfoRequest();

    this.WorkListActionObj = new WorkListActionRequest();

    this.WorkListBodyObj.P_TRANSACTION_ID = this.TransactionID;
    this.WorkListBodyObj.P_NOTIFICATION_ID = this.getPassNotificationDetails.NOTIFICATION_ID;
    this.WorkListBodyObj.P_PAGE_NUM = 1;
    this.WorkListBodyObj.P_PAGE_LIMIT = 100;

    this.WorkListButtonsObj.P_NOTIFICATION_ID = this.getPassNotificationDetails.NOTIFICATION_ID;

    this.WorkListActionObj.P_NOTIFICATION_ID = this.getPassNotificationDetails.NOTIFICATION_ID;
    this.WorkListActionObj.P_FORWARD_TO_USER_NAME = "";
    this.WorkListActionObj.P_ACTION_MODE = "";
    this.WorkListActionObj.P_COMMENTS = "";
    this.WorkListActionObj.P_APPROVER_INDEX = null;

    this.WorkListActionHistoryObj.P_PAGE_NUM = 1;
    this.WorkListActionHistoryObj.P_PAGE_LIMIT = this.P_PAGE_LIMIT;
    this.WorkListActionHistoryObj.P_NOTIFICATION_ID = this.getPassNotificationDetails.NOTIFICATION_ID;
    this.WorkListAttachObj.P_NOTIFICATION_ID = this.getPassNotificationDetails.NOTIFICATION_ID;


    this.WorkListSubmitterInfoObj.P_PAGE_LIMIT = this.P_PAGE_LIMIT;
    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.getNotificationButtons(this.WorkListButtonsObj);
    this.getNotificationResAttr(this.WorkListButtonsObj);
    this.getAttachmentNotification(this.WorkListAttachObj);
    this.getActionHistory(this.WorkListActionHistoryObj);

    if (this.getPassNotificationDetails.REQUEST_TYPE == "EIT") {
      this.getEITNotificationDetails(this.WorkListBodyObj);
    } else if (this.getPassNotificationDetails.REQUEST_TYPE == "ABSENCE") {
      this.getAbsenceNotificationDetails(this.WorkListBodyObj);
    } else if (this.getPassNotificationDetails.REQUEST_TYPE == "PO") {
      this.getPONotificationDetails(this.WorkListBodyObj);
    } else if (this.getPassNotificationDetails.REQUEST_TYPE == "MO") {
      this.getMONotificationDetails(this.WorkListBodyObj);
    } else if (this.getPassNotificationDetails.REQUEST_TYPE == "PR") {
      this.getPRNotificationDetails(this.WorkListBodyObj);
    } else if (this.getPassNotificationDetails.REQUEST_TYPE === 'ADDRESS') {
      this.getAddressNotification(this.WorkListBodyObj);
    } else if (this.getPassNotificationDetails.REQUEST_TYPE === 'BASIC_DETAILS') {
      this.getBasicDetailsNotification(this.WorkListBodyObj);
    } else if (this.getPassNotificationDetails.REQUEST_TYPE === 'STAMP_MS') {
      this.getStampMSNotification(this.WorkListBodyObj);
    } else if (this.getPassNotificationDetails.REQUEST_TYPE === 'STAMP_NS') {
      this.getStampNSNotification(this.WorkListBodyObj);
    } else if (this.getPassNotificationDetails.REQUEST_TYPE === 'TERMINATION') {
      this.getTerminationNotificationDetails(this.WorkListBodyObj);
    } else if (this.getPassNotificationDetails.REQUEST_TYPE === 'PHONE_NUMBERS') {
      this.getPhoneNotificationDetails(this.WorkListBodyObj);
    } else if (this.getPassNotificationDetails.REQUEST_TYPE === 'CONTACT') {
      this.getContactNotificationDetails(this.WorkListBodyObj);
    } else if (this.getPassNotificationDetails.REQUEST_TYPE === 'CEI') {
      this.getCEINotification(this.WorkListBodyObj);
    }
  }

  getStampMSNotification(notificationBodyObj) {
    this.worklistMainService
      .getStampMSNotificationBody(notificationBodyObj)
      .subscribe((result: PRNotificatonBodyResponse) => {
        this.handleWorkListBodyResult(result, "STAMP_MS");
      });
  }

  getStampNSNotification(notificationBodyObj) {
    this.worklistMainService
      .getStampNSNotificationBody(notificationBodyObj)
      .subscribe((result: PRNotificatonBodyResponse) => {
        this.handleWorkListBodyResult(result, "STAMP_NS");
      });
  }

  getTerminationNotificationDetails(notificationBodyObj) {
    this.worklistMainService
      .getTerminationNotificationBody(notificationBodyObj)
      .subscribe((result: PRNotificatonBodyResponse) => {
        this.handleWorkListBodyResult(result, "TERMINATION");
      });
  }

  getPhoneNotificationDetails(notificationBodyObj) {
    this.worklistMainService
      .getPhoneNotificationBody(notificationBodyObj)
      .subscribe((result: PRNotificatonBodyResponse) => {
        this.handleWorkListBodyResult(result, "PHONE_NUMBERS");
      });
  }

  getContactNotificationDetails(notificationBodyObj) {
    this.worklistMainService
      .getContactNotificationBody(notificationBodyObj)
      .subscribe((result: PRNotificatonBodyResponse) => {
        this.handleWorkListBodyResult(result, "CONTACT");
      });
  }

  getBasicDetailsNotification(notificationBodyObj) {
    this.worklistMainService
      .getBasicDetailNotificationBody(notificationBodyObj)
      .subscribe((result: PRNotificatonBodyResponse) => {
        this.handleWorkListBodyResult(result, "BASIC_DETAILS");
      });
  }
  getAddressNotification(notificationBodyObj) {
    this.worklistMainService
      .getAddressNotificationBody(notificationBodyObj)
      .subscribe((result: PRNotificatonBodyResponse) => {
        this.handleWorkListBodyResult(result, "ADDRESS");
      });
  }

  getCEINotification(notificationBodyObj) {
    this.worklistMainService
      .getCEINotificationBody(notificationBodyObj)
      .subscribe((result: MONotificatonBodyResponse) => {
        this.handleWorkListBodyResult(result, "CEI");
      });
  }

  getPRNotificationDetails(notificationBodyObj) {
    this.worklistMainService
      .getPRNotificationBody(notificationBodyObj)
      .subscribe((result: PRNotificatonBodyResponse) => {
        this.handleWorkListBodyResult(result, "PR");
      });
  }

  getMONotificationDetails(notificationBodyObj) {
    this.worklistMainService
      .getMONotificationBody(notificationBodyObj)
      .subscribe((result: MONotificatonBodyResponse) => {
      });
  }

  getPONotificationDetails(notificationBodyObj) {
    this.worklistMainService
      .getPONotificationBody(notificationBodyObj)
      .subscribe((result: PONotificatonBodyResponse) => {
      });
  }

  getEITNotificationDetails(notificationBodyObj) {
    this.notificationBodyRes = []
    this.worklistMainService
      .getEITNotificationBody(notificationBodyObj)
      .subscribe((result: EITNotificatonBodyResponse) => {
        this.handleWorkListBodyResult(result, "EIT");
      });
  }

  getAbsenceNotificationDetails(notificationBodyObj) {
    this.notificationBodyRes = [];
    this.worklistMainService
      .getAbsencesNotificationBody(notificationBodyObj)
      .subscribe((result: AbsenceNotificatonBodyResponse) => {
        this.handleWorkListBodyResult(result, "ABSENCE");
      });
  }

  handleWorkListBodyResult(result, Type) {
    this.showInformation = false;
    if (this.common.validResponse(result)) {
      this.pInformation = result.P_INFORMATION;
      this.pQuestion = result.P_QUESTION;
      if (Type == "EIT") {
        if (result.GetEITCollectionNotificationBodyList) {
          this.notificationBodyRes =
            result.GetEITCollectionNotificationBodyList;
          if (this.notificationBodyRes[0].Collection_Notification) {
            console.log(this.notificationBodyRes[0].Collection_Notification);
          }
        }
      } else if (Type == "ABSENCE") {
        if (result.GetAbsenceCollectionNotificationBodyList) {
          this.notificationBodyRes =
            result.GetAbsenceCollectionNotificationBodyList;
          if (this.notificationBodyRes[0].Collection_Notification) {
            console.log(this.notificationBodyRes[0].Collection_Notification);
          }

          let obj = (this.notificationBodyRes[0].Collection_Notification).filter(function (list) {
            return list.SEGMENT_NAME === "END_DATE" || list.SEGMENT_NAME === "START_DATE";
          });

          this.getSubordinatesleave(obj)
        }
      } else if (Type === "PR") {
        if (result.GetAbsenceCollectionNotificationBodyList) {
          this.notificationBodyRes =
            result.GetAbsenceCollectionNotificationBodyList;
        }
      } else if (Type === "ADDRESS") {
        console.log(result.GetAddressNotificationBodyList)
        if (result.GetAddressNotificationBodyList) {
          this.notificationBodyRes =
            result.GetAddressNotificationBodyList;
          console.log(result);
        }
      } else if (Type === "BASIC_DETAILS") {
        if (result.GetBasicDetNtfBodyList) {
          this.notificationBodyRes =
            result.GetBasicDetNtfBodyList;
          console.log(result);
        }
      } else if (Type === "CEI") {
        if (result.GetCEICollectionNotificationBodyList) {
          this.notificationBodyRes =
            result.GetCEICollectionNotificationBodyList[0].Collection_Notification;
          console.log(result.GetCEICollectionNotificationBodyList[0].Collection_Notification);
        }
      }
      else if (Type === "STAMP_MS") {
        if (result.GetStampMsNotificationBodyList) {
          this.stampMsNotificationBodyRes =
            result.GetStampMsNotificationBodyList;
          console.log(result);
        }
      }
      else if (Type === "STAMP_NS") {
        if (result.GetStampNsNotificationBodyList) {
          this.stampNsNotificationBodyRes =
            result.GetStampNsNotificationBodyList;
          console.log(result);
        }
      }
      else if (Type === "PHONE_NUMBERS") {
        if (result.GetPhonesNotificationBodyList) {
          this.notificationBodyRes =
            result.GetPhonesNotificationBodyList;
          console.log(result);
        }
      }
      else if (Type === "TERMINATION") {
        if (result.GetTermNotificationBodyList) {
          this.notificationBodyRes =
            result.GetTermNotificationBodyList;
          console.log(result);
        }
      }
      else if (Type === "CONTACT") {
        if (result.GetContactNotificationBodyList) {
          this.notificationBodyRes =
            result.GetContactNotificationBodyList.ContactNotificationBody;
          console.log(result);
        }
      }
    }
  } //End handleWorkListBodyResult

  getNotificationButtons(notificationButtonsObj) {
    this.notificationButtonRes = [];
    this.worklistMainService
      .getNotificationButtons(notificationButtonsObj)
      .subscribe((result: NotificatonButtonResponse) => {
        this.handleWorkListButtonsResult(result);
      });
  }

  handleWorkListButtonsResult(result) {
    if (this.common.validResponse(result)) {
      // this.sharedData.setSharedData(result, WorKListResponse.SHARED_DATA);
      if (result.GetNotificationButtonsList != null) {
        this.notificationButtonRes = result.GetNotificationButtonsList;
        this.common.sharedService.setSharedData(this.notificationButtonRes, "passActionMore");
        console.log("test" + this.notificationButtonRes.length);
        for (let i = 0; i < this.notificationButtonRes.length; i++) {
          if (this.notificationButtonRes[i].BUTTON_ACTION == "APPROVED") {
            this.approve_label = this.notificationButtonRes[i].BUTTON_LABEL;
            this.approveDis = true;
          } else
            if (this.notificationButtonRes[i].BUTTON_ACTION == "REJECTED") {
              this.reject_label = this.notificationButtonRes[i].BUTTON_LABEL;
              this.rejectDis = true;
            } else
              if (this.notificationButtonRes[i].BUTTON_ACTION == "REQUEST_INFO") {
                this.reqInfo_label = this.notificationButtonRes[i].BUTTON_LABEL;
                this.requestDis = true;
              } else if // if result == null
                (this.notificationButtonRes[i].BUTTON_ACTION == "CLOSE") {
                this.close_label = this.notificationButtonRes[i].BUTTON_LABEL;
                this.closeDis = true;
              } else if

                (this.notificationButtonRes[i].BUTTON_ACTION != "APPROVED" && this.notificationButtonRes[i].BUTTON_ACTION != "REJECTED" && this.notificationButtonRes[i].BUTTON_ACTION != "REQUEST_INFO" && this.notificationButtonRes[i].BUTTON_ACTION != "CLOSE") {
                this.moreDisabled = false;

              }
        }
      }
    }
  } // End handleWorkListButtonsResult

  applyAction(WorkListActionObj) {
    console.log("MemberLoginList");
    this.worklistMainService
      .actionButton(WorkListActionObj)
      .subscribe((result: any) => {
        this.handleApplayActionResult(result);
      });
  }

  handleApplayActionResult(result) {
    if (this.common.validResponse(result)) {
      // tslint:disable-next-line: triple-equals
      if (result.MessageStatus == 1) {
        this.common.sharedService.setSharedData(true, 'loadWorkList');
        // this.navCtrl.push("HomePage");
        // this.common.openHome();
        // this.common.openNotificationPage();
        //   for( var i = 0; i < this.notificationArray.length; i++){
        //     if ( this.notificationArray[i].ROW_NUM === this.getPassNotificationDetails.ROW_NUM) {
        //       this.notificationArray.splice(i, 1);
        //     }
        //  }
        // this.messageSuccess = true;
        this.common.greenToastPK('worklist', 'done-successfully');
        this.common.setTotalNumberOfWorklistRequest();
        setTimeout(() => {
          this.nextNotfification();
        }, 300);
      } else {
        this.common.redToastPK('worklist', 'save-error');
      }
    } // valid it
  }

  // public nextNotfification() {
  //   //let itemExist = false;


  //   let itemNo = this.getPassNotificationDetails.ROW_NUM;
  //   itemNo += 1;

  //   if (itemNo > this.notificationArray.length) {
  //     this.common.openNotificationPage();
  //   } else {
  //     for (let i = 0; i < this.notificationArray.length; i++) {
  //       if (this.notificationArray[i].ROW_NUM == itemNo) {
  //         this.common.sharedService.setSharedData(this.notificationArray[i], HomeComponent.NOTIFICATION_DATA);
  //         // itemExist = true;
  //         this.intializeNotificationDetail();
  //         break;
  //       }
  //     }
  //     //     if(itemExist==false){
  //     // this.nextNotfification();
  //     //     }
  //   }
  // }


  public nextNotfification(flag?) {
    if (document.getElementById("notificationDynamicFields") != null) {
      document.getElementById("notificationDynamicFields").innerHTML = "";
    }

    let itemNo = this.getPassNotificationDetails.ROW_NUM;
    console.log(itemNo);
    let index = this.notificationArray.findIndex(x => x.ROW_NUM === itemNo);
    console.log(index);
    console.log(this.notificationArray);
    let previousRequest = this.notificationArray[index].REQUEST_TYPE;
    let itemType = this.notificationArray[index].ITEM_TYPE;
    if (previousRequest == 'STAMP_MS' || previousRequest == 'STAMP_NS') {
      previousRequest = 'STAMP';
    } else {
      previousRequest = itemType;
    }
    if (this.common.filterKeys[previousRequest] != 0 && flag != 'skip')
      this.common.filterKeys[previousRequest] = (this.common.filterKeys[previousRequest] - 1)

    index += 1;
    if (index < this.notificationArray.length) {
      this.activeSegment = 'info';
      if (this.selectedFilter === 'ALL') {
        this.common.sharedService.setSharedData(this.notificationArray[index], HomeComponent.NOTIFICATION_DATA);
        this.checkRequestType(index);
      } else {
        if (this.arr_hr_req_only) {
          let requestIndex = this.arr_hr_req_only.findIndex(x => x.ROW_NUM === itemNo);
          requestIndex++;
          if (requestIndex < this.arr_hr_req_only.length) {
            this.common.sharedService.setSharedData(this.arr_hr_req_only[requestIndex], HomeComponent.NOTIFICATION_DATA);
            this.intializeNotificationDetail();
          } else {
            this.common.sharedService.setSharedData(true, HomeComponent.COUNT_CHANGED);
            //this.common.setTotalNumberOfWorklistRequest(true);
            this.common.openNotificationPage();
          }
        }
      }
    } else {
      this.common.sharedService.setSharedData(true, HomeComponent.COUNT_CHANGED);
      //this.common.setTotalNumberOfWorklistRequest(true);
      this.common.openNotificationPage();
    }

    // if (index < this.notificationArray.length) {
    //   this.common.sharedService.setSharedData(this.notificationArray[index], HomeComponent.NOTIFICATION_DATA);
    //   this.activeSegment = 'info';
    //   if (this.selectedFilter === 'ALL') {
    //     this.checkRequestType(index);
    //   } else if (previousRequest === this.notificationArray[index].REQUEST_TYPE) {
    //     this.checkRequestType(index);
    //   } else if((this.notificationArray[index].ITEM_TYPE === 'HRSSA' && this.notificationArray[index].REQUEST_TYPE === 'EIT') ||
    //    (this.notificationArray[index].ITEM_TYPE === 'HRSSA' && this.notificationArray[index].REQUEST_TYPE === 'ABSENCE')){
    //     this.checkRequestType(index);
    //   } else {
    //     this.common.openNotificationPage();
    //   }
    // } else {
    //   this.common.openNotificationPage();
    // }
  }

  checkRequestType(index) {
    if (this.notificationArray[index].REQUEST_TYPE === 'PO') {
      this.common.openWorklistMainPOPage();
    } else
      if (this.notificationArray[index].REQUEST_TYPE === 'PR') {
        this.common.openWorklistMainPRPage();
      } else
        if (this.notificationArray[index].REQUEST_TYPE === 'MO') {
          this.common.openWorklistMainMRPage();
        } else {
          this.intializeNotificationDetail();
        }
  }


  sortArray(arrayToSort: any) {
    return arrayToSort.sort((a: any, b: any) =>
      new Date(b.BEGIN_DATE).getTime() - new Date(a.BEGIN_DATE).getTime()
    );
  }

  actionButton(action) {
    //let ButtonAction: string = this.actionType;
    let ButtonAction: string = action;
    var responseAttrDic = this.notExampleJsonObject;
    this.P_RESPOND_ATTRIBUTES_TBL = [];
    for (let i = 0; i < this.notificationDynamicAttributeArr.length; i++) {
      let obj: any = {};
      obj.ATTRIBUTE_NAME = this.notificationDynamicAttributeArr[i].ATTRIBUTE_NAME;
      if (this.notificationDynamicAttributeArr[i].ATTRIBUTE_TYPE === "number") {
        obj.ATTRIBUTE_NUMBER_VALUE = (document.getElementById(this.notificationDynamicAttributeArr[i].ATTRIBUTE_NAME) as HTMLInputElement).value;
      }
      else if (this.notificationDynamicAttributeArr[i].ATTRIBUTE_TYPE == "VARCHAR2") {
        obj.ATTRIBUTE_TEXT_VALUE = (document.getElementById(this.notificationDynamicAttributeArr[i].ATTRIBUTE_NAME) as HTMLInputElement).value;
      }
      this.P_RESPOND_ATTRIBUTES_TBL.push(obj);
    }
    console.log("a" + this.P_RESPOND_ATTRIBUTES_TBL);

    let repUserName = this.selEmployeeID;
    if (this.hideForwordEmployee && this.hideForwordEmployee.ATTRIBUTE_NAME) {
      let obj: any = {};
      repUserName = "";
      obj.ATTRIBUTE_NAME = this.hideForwordEmployee.ATTRIBUTE_NAME;
      obj.ATTRIBUTE_TEXT_VALUE = this.selEmployeeID;
      this.P_RESPOND_ATTRIBUTES_TBL.push(obj);
    }

    if (
      ButtonAction == "APPROVED" ||
      ButtonAction == "REJECTED" ||
      ButtonAction == "DEL" ||
      ButtonAction == "CLOSE"
    ) {
      this.WorkListActionObj.P_FORWARD_TO_USER_NAME = "";
      this.WorkListActionObj.P_ACTION_MODE = ButtonAction;
      this.WorkListActionObj.P_COMMENTS = "";
      this.WorkListActionObj.RespondAttributeList = this.P_RESPOND_ATTRIBUTES_TBL;

      this.common.sharedService.setSharedData(
        this.getPassNotificationDetails,
        WorklistMainComponent.PASS_NOTIFICATION_INFO
      );
      this.common.sharedService.setSharedData(
        ButtonAction,
        WorklistMainComponent.PASS_ACTION_MODE
      );

      this.common.sharedService.setSharedData(
        this.P_RESPOND_ATTRIBUTES_TBL,
        WorklistMainComponent.PASS_RES_ATTR
      );

      if (ButtonAction === "APPROVED") {
        this.confirmMsg = this.ts.trPK('worklistMain', 'approveMsg')
      }
      else if (ButtonAction === "REJECTED") {
        this.confirmMsg = this.ts.trPK('worklistMain', 'rejectMsg')

      }
      else if (ButtonAction === "DEL") {
        this.confirmMsg = this.ts.trPK('worklistMain', 'delMsg')

      }
      else if (ButtonAction === "CLOSE") {
        this.confirmMsg = this.ts.trPK('worklistMain', 'closeMsg')
      }

      this.common.confirmAlertDialogAction(
        () => {
          this.applyAction(this.WorkListActionObj);
        }, this.ts.trPK('general', 'ok'),
        () => { }, this.ts.trPK('general', 'cancel'),
        this.ts.trPK('vacation-rule', 'confirmation'),
        this.confirmMsg)
    }

    if (ButtonAction == "RFC") {
      // alert("Return For Correction");
      this.WorkListActionObj.P_ACTION_MODE = ButtonAction;

      this.common.sharedService.setSharedData(
        this.getPassNotificationDetails,
        WorklistMainComponent.PASS_NOTIFICATION_INFO
      );
      this.common.sharedService.setSharedData(
        ButtonAction,
        WorklistMainComponent.PASS_ACTION_MODE
      );
      this.common.sharedService.setSharedData(
        this.P_RESPOND_ATTRIBUTES_TBL,
        WorklistMainComponent.PASS_RES_ATTR
      );
      //this.common.openWorklistRFCPage();
      this.openRFCModal();
    } else if (ButtonAction == "ANSWER_INFO") {
      this.common.sharedService.setSharedData(this.pQuestion, "pQuestion");
      this.common.sharedService.setSharedData(
        this.getPassNotificationDetails,
        WorklistMainComponent.PASS_NOTIFICATION_INFO
      );
      this.common.sharedService.setSharedData(
        ButtonAction,
        WorklistMainComponent.PASS_ACTION_MODE
      );
      this.common.sharedService.setSharedData(
        this.P_RESPOND_ATTRIBUTES_TBL,
        WorklistMainComponent.PASS_RES_ATTR
      );
      //this.common.openWorklistRollReplacement();
      this.openRepRolModal();
    } else if (
      ButtonAction == "DELEGATE" ||
      ButtonAction == "REQUEST_INFO" ||
      ButtonAction == "TRANSFER" ||
      ButtonAction == "TRANSFER_INFO"
    ) {
      //   alert("multi option: "+ ButtonAction);
      this.WorkListActionObj.P_ACTION_MODE = ButtonAction;
      this.common.sharedService.setSharedData(
        this.getPassNotificationDetails,
        WorklistMainComponent.PASS_NOTIFICATION_INFO
      );
      this.common.sharedService.setSharedData(
        ButtonAction,
        WorklistMainComponent.PASS_ACTION_MODE
      );
      this.common.sharedService.setSharedData(
        this.P_RESPOND_ATTRIBUTES_TBL,
        WorklistMainComponent.PASS_RES_ATTR
      );
      console.log("c" + this.P_RESPOND_ATTRIBUTES_TBL);
      this.openRepRolModal();
    } else if (
      ButtonAction == "UPDATE_ACTION" ||
      ButtonAction == "CONTINUE_ACTION"
    ) {
      if (this.getPassNotificationDetails.REQUEST_TYPE == "EIT") {
        this.common.sharedService.setSharedData(
          this.notificationBodyRes,
          EITNotificatonBodyResponse.SHARED_DATA
        );
        this.common.sharedService.setSharedData(
          this.getPassNotificationDetails,
          EITNotificatonBodyResponse.NOT_WORKLIST
        );
        // this.navCtrl.push("EitUpdateListPage");
        this.common.eitUpdate();// must be test
      } else if (this.getPassNotificationDetails.REQUEST_TYPE == "ABSENCE") {
        this.common.sharedService.setSharedData(
          this.notificationBodyRes,
          AbsenceNotificatonBodyResponse.SHARED_DATA
        );
        this.common.sharedService.setSharedData(
          this.getPassNotificationDetails,
          AbsenceNotificatonBodyResponse.NOT_WORKLIST
        );
        this.dirfromNotificationPage = true,
          this.common.sharedService.setSharedData(
            this.dirfromNotificationPage,
            "dirfromNotificationPage"
          );
        this.common.sharedService.setSharedData(
          this.notificationBodyRes[0].Collection_Notification,
          "submitAbsObjList"
        );

        this.common.openSubmitAbsencePage();
      }
    }
    else if (this.notificationButtonRes.length > 0 && !ButtonAction) {
      (this.elementRef.nativeElement.querySelectorAll(
        "ion-item"
      ) as HTMLElement[]).forEach(x => {
        if (x.classList.contains("requiredItem")) {
          x.classList.add("ng-touched");
          x.classList.remove("ng-untouched");
        }
      });
      this.common.presentAlert(
        this.ts.trPK("worklistMain", "actionRequird")
      );
    }
  }

  openActionHistory() {
    this.common.sharedService.setSharedData(
      this.getPassNotificationDetails,
      WorklistMainComponent.PASS_NOTIFICATION_INFO
    );
    this.common.openWorklistHistoryPage();
  }

  openSupportDocuments() {
    this.common.sharedService.setSharedData(
      this.getPassNotificationDetails,
      WorklistMainComponent.PASS_NOTIFICATION_INFO
    );
    this.common.openWorklistAttachPage();
  }

  getNotificationResAttr(notificationButtonsObj) {
    console.log("getNotificationResAttr");
    this.worklistMainService
      .notificationResponseAttr(notificationButtonsObj)
      .subscribe((result: NotificatonButtonResponse) => {
        this.handleNotificationResAttrResult(result);
      });
  }

  handleNotificationResAttrResult(result) {
    if (this.common.validResponse(result)) {
      this.NotRespondAttributeList = [];
      result.NotificationGetRespondAttributesList;
      if (
        result.NotificationRespondRolesList != "" &&
        result.NotificationRespondRolesList[0].ATTRIBUTE_NAME != null &&
        result.NotificationRespondRolesList[0].ATTRIBUTE_NAME != undefined
      ) {
        this.Resp2_val = result.NotificationRespondRolesList[0].ATTRIBUTE_NAME;
        this.hideForwordEmployee = result.NotificationRespondRolesList[0];
      }
      this.notificationDynamicFields(result.NotificationGetRespondAttributesList);
      this.notificationDynamicAttributeArr = result.NotificationGetRespondAttributesList;
      this.common.sharedService.setSharedData(
        this.notificationDynamicAttributeArr,
        "notificationDynamicAttributeArr"
      );
      if (result.P_Schema) this.schemaNotific = JSON.parse(result.P_Schema);
    } // valid it
  } // End handleWorkListButtonsResult

  notificationDynamicFields(notificationAttr) {
    const containerId = 'notificationDynamicFields';
    for (let i = 0; i < notificationAttr.length; i++) {
      if (notificationAttr[i].ATTRIBUTE_TYPE == "VARCHAR2") {
        this.textArea = new TextAreaInput(notificationAttr[i].ATTRIBUTE_DISPLAY_NAME, notificationAttr[i].ATTRIBUTE_NAME, "", containerId, "", "", "");
        console.log(this.textArea);
      } else if (notificationAttr[i].ATTRIBUTE_TYPE == "ROLE") {

      } else if (notificationAttr[i].ATTRIBUTE_TYPE == "DATE") {

      } else if (notificationAttr[i].ATTRIBUTE_TYPE == "NUMBER") {

      }
    }
  }

  openNotificationBody() {
    if (this.getPassNotificationDetails.REQUEST_TYPE == "EIT") {
      this.common.sharedService.setSharedData(
        this.notificationBodyRes,
        EITNotificatonBodyResponse.SHARED_DATA
      );
      this.common.sharedService.setSharedData(
        this.getPassNotificationDetails,
        EITNotificatonBodyResponse.NOT_WORKLIST
      );
      // this.navCtrl.push("WorkListDetailsPage", { NotBodyType: "EIT" });
      this.common.sharedService.setSharedData("EIT", "NotBodyType");
      this.common.openNotificationDetailsPage();
    } else if (this.getPassNotificationDetails.REQUEST_TYPE == "ABSENCE") {
      this.common.sharedService.setSharedData(
        this.notificationBodyRes,
        AbsenceNotificatonBodyResponse.SHARED_DATA
      );
      this.common.sharedService.setSharedData(
        this.getPassNotificationDetails,
        AbsenceNotificatonBodyResponse.NOT_WORKLIST
      );
      this.common.sharedService.setSharedData("ABSENCE", "NotBodyType");
      this.common.openNotificationDetailsPage();
    }
  }

  // getNotificationCountAfterSubmit() {
  //   const req: any = {};
  //   this.menuService.getNotificationCount(req).subscribe((result: any) => {
  //     if (this.common.validResponse(result)) {
  //       this.notificationCount =
  //         result.GetOpenNotificationsNumList.P_OPEN_NOTIFICATIONS_NUM;
  //       if (this.notificationCount <= 0) {
  //         this.notificationCount = null;
  //       }
  //       this.events.publish("getNotCount", this.notificationCount);
  //     }
  //   });
  // }

  getAttachmentNotification(WorkListAttachObj) {
    this.attachmentRes = []
    console.log(" this.P_PAGE_NUM: " + this.P_PAGE_NUM);

    this.worklistAttachService.getAttach(WorkListAttachObj).
      subscribe((result: NotificationGetAttachResponse) => {
        this.handleWorkListAttachResult(result);
      });
  }

  handleWorkListAttachResult(result) {
    if (this.common.validResponse(result)) {
      // this.sharedData.setSharedData(result, WorKListResponse.SHARED_DATA);
      if (result.GetAttachementList != null) {
        this.attachmentRes = result.GetAttachementList;
      } // if result == null
    } // valid it
  }

  getActionHistory(WorkListActionHistoryObj) {
    this.IsReachEnd = true;
    this.actionHistoryRes = [];
    console.log(" this.P_PAGE_NUM: " + this.P_PAGE_NUM);
    this.worklistService.getActionHistory(WorkListActionHistoryObj).
      subscribe((result: WorkListActionHistoryResponse) => {
        this.handleWorkListActionHistoryResult(result);
      });


  }
  handleWorkListActionHistoryResult(result) {
    console.log("1" + this.IsReachEnd);
    if (this.common.validResponse(result)) {
      if (this.common.hasData(result.GetActionHistoryList)) {
        this.actionHistoryRes = result.GetActionHistoryList;
        this.P_PAGE_NUM++;
        this.WorkListActionHistoryObj.P_PAGE_NUM = this.P_PAGE_NUM;
        let lastItemIndex = this.actionHistoryRes.length - 1;
        if (result.GetActionHistoryList[lastItemIndex]) {
          let lastitem = result.GetActionHistoryList[lastItemIndex];
          if (lastitem.NO_OF_ROWS == lastitem.ROW_NUM) {
            this.IsReachEnd = true;
            console.log("2" + this.IsReachEnd);

          } else {
            this.IsReachEnd = false;
            console.log("3" + this.IsReachEnd);

          }
        }
        this.turnCateFun(this.actionHistoryRes);

      }
    }
  }

  public formatJobName(title: any) {
    let jobName: any;
    if (title) {
      let jobTitle = title.split('.');
      if (jobTitle && jobTitle.length > 1) {
        jobName = jobTitle[0] + " " + jobTitle[1];
      }
    } else {
      jobName = '';
    }
    return jobName;
  }

  public checkLines(note) {
    if (note && note != null) {
      return (note.length > this.lines_note_limit) ? true : false;
    }
    return false;
  };

  public turnCateFun(actionHis) {
    for (let i = 0; i < actionHis.length; i++) {
      actionHis[i].visible = false;
    }
    this.actionHistoryRes = actionHis;

    console.log("test");
  }

  async openMoreActions() {
    const modal = await this.modalCtrl.create({
      component: MoreActionModalComponent,
      backdropDismiss: false,
    });
    modal.cssClass = 'note-modal';
    modal.onDidDismiss()
      .then((data) => {
        console.log(data.data);
        if (data.data == "cancel" || data.data == undefined) {
          return;
        } else {
          // this.selectedAction = data.data;
          this.actionType = data.data.BUTTON_ACTION;
          console.log(this.actionType);
          ///call  Action button
          this.actionButton(this.actionType);
        }
      });
    return await modal.present();
  }

  async OpenAttachFiles(value, Type) {
    this.common.sharedService.setSharedData({ displayData: value, TypeData: Type }, 'WorkListAttachViewPage')
    const modal = await this.modalCtrl.create({
      component: WorkListAttachViewComponent
    });
    return await modal.present();
  }


  ///calling getSubleave

  getSubordinatesleave(list) {
    console.log(list);
    let to;
    let from;
    for (let i = 0; i < list.length; i++) {
      if (list[i].SEGMENT_NAME == "END_DATE")
        to = list[i].DATE_VALUE;

      else if (list[i].SEGMENT_NAME == "START_DATE") {
        from = list[i].DATE_VALUE;
      }
    }
    const request = new GetSubordinatesLeavesRequest();
    request.P_DATE_FROM = "/Date(" + Date.parse(from) + '+0300' + ")/";//new Date(from);
    request.P_DATE_TO = "/Date(" + Date.parse(to) + '+0300' + ")/" //new Date(to);
    request.P_SELECTED_EMPLOYEE_NUMBER = this.selEmp;
    this.dashboredService.getSubordinatesLeaves(request).
      subscribe((result: any) => {
        this.handleSubordinatesLeavesResult(result);
      });
  }

  public handleSubordinatesLeavesResult(result) {
    if (this.common.validResponse(result)) {
      if (this.common.hasData(result.SubordinatesOnLeavesList)) {
        this.allSubordinatesleaveList = result.SubordinatesOnLeavesList;
        // this.subordinatesleaveList.push(this.allSubordinatesleaveList.find(
        //   el => el.EMPLOYEE_NUMBER !== this.getPassNotificationDetails.SELECTED_EMPLOYEE_NUMBER));
        this.allSubordinatesleaveList.forEach(element => {
          if (element.EMPLOYEE_NUMBER !== this.getPassNotificationDetails.SELECTED_EMPLOYEE_NUMBER) {
            this.subordinatesleaveList.push(element);
          }
        });
      }
    }
  }

  getsubmitterInfo(notificationSubmitterInfoObj) {
    this.submitterInfoRes = [];
    this.worklistMainService.getSubmitterInfo(notificationSubmitterInfoObj).
      subscribe((result: WorklistsubmitterInfoResponse) => {
        this.handleSubmitterInfoResult(result);
      });
  }

  handleSubmitterInfoResult(result) {
    if (this.common.validResponse(result)) {
      // this.sharedData.setSharedData(result, WorKListResponse.SHARED_DATA);
      if (this.common.hasData(result.MemberInformationList)) {
        //if (result.MemberInformationList != null) {
        this.submitterInfoRes = result.MemberInformationList;
      } // if result == null
    } // valid it
  }// End handleWorkListButtonsResult

  async openRepRolModal() {
    this.common.sharedService.setSharedData(this.actionHistoryRes, 'actionHistoryData');
    const modal = await this.modalCtrl.create({
      component: WorkListReplacementRollComponent,
      backdropDismiss: false,
    });
    modal.cssClass = 'replaceRoll-modal2';
    modal.onDidDismiss()
      .then((data) => {
        if (data.data.data == "cancel" || data.data.data == undefined) {
          return;
        } else if (data.data.data == "Success") {
          // this.messageSuccess = true;
          this.common.greenToastPK('worklist', 'done-successfully');
          this.common.setTotalNumberOfWorklistRequest();
          setTimeout(() => {
            // this.messageSuccess = false;
            this.nextNotfification();
          }, 300);
          // this.nextNotfification();
        } else {
          this.common.redToastPK('worklist', 'save-error');
        }
      });
    return await modal.present();
  }

  async openRFCModal() {
    const modal = await this.modalCtrl.create({
      component: WorkListRfcComponent,
      backdropDismiss: false,
    });
    modal.cssClass = 'replaceRoll-modal';
    modal.onDidDismiss()
      .then((data) => {
        console.log(data.data);
        if (data.data == "cancel" || data.data == undefined) {
          return;
        } else if (data.data == "Success") {
          // this.openNotificationsDashboard();
          this.common.setTotalNumberOfWorklistRequest();
          this.nextNotfification();
        }
      });
    return await modal.present();
  }

  async openApplyModal(WorkListActionObj) {
    this.common.sharedService.setSharedData(this.getPassNotificationDetails, WorklistMainComponent.PASS_NOTIFICATION_INFO);
    this.common.sharedService.setSharedData(WorkListActionObj, 'ApplyActionModalPage')
    const modal = await this.modalCtrl.create({
      component: ApplyActionModalComponent,
      backdropDismiss: false,
    });
    modal.cssClass = 'note-modal';
    modal.onDidDismiss()
      .then((data) => {
        console.log(data); // Here's your selected user!
      });
    return await modal.present();
  }

  loadMoreActionHistory() {
    if (!this.IsReachEnd) {
      console.log("doInfinite action history MR");
      this.worklistService.getActionHistory(this.WorkListActionHistoryObj).
        subscribe((result: any) => {
          if (this.common.validResponse(result)) {
            if (result.GetActionHistoryList != undefined) {
              this.P_PAGE_NUM++;
              this.WorkListActionHistoryObj.P_PAGE_NUM = this.P_PAGE_NUM;
              (result.GetActionHistoryList).forEach(element => {
                if (element.ROW_NUM == element.NO_OF_ROWS) {
                  this.IsReachEnd = true;
                } else {
                  this.IsReachEnd = false;
                }
                this.actionHistoryRes.push(element);
              }, (Error) => console.log(Error), () =>
                //infiniteScroll.target.complete()
                console.log("TEST"));
            }// if list length >0
            else {
              this.IsReachEnd = true;
            }
          }// if response == 1
          //this.pageNum++;
          //  infiniteScroll.target.complete();
        });
    } else {
      console.log("no doInfinite action history MR");
    }
  }//end infiniteScroll

  openNotificationsDashboard() {
    this.dashboredService.getOpenNotifications('', '', this.isPostNoLoad).subscribe((result: GetOpenNotificationsResponse) => {
      if (this.common.validResponse(result)) {
        this.worklistNotifications = result;
        this.totalRequestCount = this.worklistNotifications.P_OPEN_NTF_NUMBER;
        this.common.sharedService.setSharedData(result, 'worklistNotifications');
      }
    });
  }
  openRequestInfoDel(userData, flag) {
    this.common.sharedService.setSharedData(userData, 'requestInfoDelUser');
    this.actionButton(flag);
  }
  sortRequests() {
    for (let i = 0; i < this.notificationArray.length; i++) {
      if (this.notificationArray[i].ITEM_TYPE === 'HRSSA' || this.notificationArray[i].ITEM_TYPE === 'STAMP') {
        this.arr_hr_req_only.push(this.notificationArray[i]);
      }
    }
    console.log(this.arr_hr_req_only);
  }

  returnDateTime(stringDate: string) {
    let allDateTime = stringDate.split(' ');
    let time = allDateTime[1].split(':', 2);
    let fullDate = this.transform(stringDate);
    return fullDate + ' ' + time[0] + ':' + time[1] + ' ' + allDateTime[2];

  }
  locale = {
    en: {
      //  month_names: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
      month_names_short: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    }
  };
  transform(value: string) {
    let x = new Date(Date.parse(value));
    //return value.toLowerCase();
    let month = this.getMonthNameShort('en', x.getMonth())
    return "" + x.getDate() + " " + month + " " + x.getFullYear();


  }



  getMonthNameShort(lang, month) {
    lang = lang && (lang in this.locale) ? lang : 'en';
    return this.locale[lang].month_names_short[month];
  }

  showLoading(notificationList) {
    if (notificationList.length < 0) {
      return true;
    } else if (notificationList === []) {
      return false;
    } else { return true; }
  }

}
