import { Component, OnInit } from '@angular/core';
import { TimeCardService } from 'src/app/time-card/service/time-card.service';
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
import { SharedDataService } from 'src/app/hmg-common/services/shared-data-service/shared-data.service';
import { GetShiftDetailRequest } from 'src/app/time-card/service/models/get-shift-detail.request';
import { GetSwipesRequest } from 'src/app/time-card/service/models/get-swipes-request';
import { MenuResponse } from 'src/app/hmg-common/services/menu/models/menu-response';
import * as moment from 'moment';

@Component({
  selector: 'app-shift-details',
  templateUrl: './shift-details.component.html',
  styleUrls: ['./shift-details.component.scss'],
})
export class ShiftDetailsComponent implements OnInit {
  public selectedShift: any;
  // public selectedShiftDay: any;
  public shiftDetailsData: any = [];
  public swipeDetailsData: any = [];
  constructor(
    public timeCardService: TimeCardService,
    public common: CommonService,
    public sharedData: SharedDataService) { }
    
  ngOnInit() {
    this.selectedShift = this.sharedData.getSharedData('selectedShift', false);
    console.log(this.selectedShift);
    if (this.selectedShift.origin === 'shiftDetails') {
        this.getScheduleShiftDetails();
    } else if (this.selectedShift.origin === 'shiftSwipes') {
        this.getSwipesDetails();
    }

    // this.selectedShiftDay = this.sharedData.getSharedData('selectedShiftDay', false);
    // console.log(this.selectedShiftDay);
    // if (this.selectedShiftDay.origin === 'shiftDetails') {
    //     this.getScheduleShiftDetails();
    // } else if (this.selectedShiftDay.origin === 'shiftSwipes') {
    //     this.getSwipesDetails();
    // }
  }

  getScheduleShiftDetails() {
    console.log("getScheduleShiftDetails");
    const GetShiftDetailRequestObject = new GetShiftDetailRequest();
    GetShiftDetailRequestObject.P_RTP_ID = this.selectedShift.RTP_ID;
    GetShiftDetailRequestObject.P_PAGE_NUM = 1;
    GetShiftDetailRequestObject.P_PAGE_LIMIT = 10;
    console.log(GetShiftDetailRequestObject);
    this.timeCardService.getShiftDetail(GetShiftDetailRequestObject).subscribe((result) => {
      if (this.common.validResponse(result)) {
          console.log(result);
          this.shiftDetailsData = result.GetScheduleShiftsDetailsList;
          // this.common.sharedService.setSharedData(this.shiftDetailsData,'shiftDetailsData');
      }
    })
  }

  getSwipesDetails() {
    console.log("getSwipesDetails");

    const GetSwipesRequestObject = new GetSwipesRequest();
    GetSwipesRequestObject.P_SELECTED_EMPLOYEE_NUMBER = this.common.sharedService.getSharedData(MenuResponse.SHARED_SEL_EMP, false);
    GetSwipesRequestObject.P_SCHEDULE_DATE = this.common.convertISODateToJsonDate(this.selectedShift.SCHEDULE_DATE);
    GetSwipesRequestObject.P_PAGE_NUM = 1;
    GetSwipesRequestObject.P_PAGE_LIMIT = 10;
    this.timeCardService.getSwipes(GetSwipesRequestObject).subscribe((result) => {
      if (this.common.validResponse(result)) {
          console.log(result);
          this.swipeDetailsData = result.GetSwipesList;
      }
    });
  }

}
