import { Component, Input, OnInit } from '@angular/core';
import { Events } from '@ionic/angular';
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service';
import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service';
import { SharedDataService } from 'src/app/hmg-common/services/shared-data-service/shared-data.service';
import { MowadhafiService } from '../mowadhafi.service';
import { Location } from '@angular/common';
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-my-request',
  templateUrl: './my-request.component.html',
  styleUrls: ['./my-request.component.scss'],
})
export class MyRequestComponent implements OnInit {
  public direction: string;
  public ticketsInfo : any = [];
  public ticketCount = 10;
  public ticketPage = 1;
  public increseCount = 0;
  public ticketTotal :any;

   @Input()
   ngClass:string |string[]| Set<string>| {[klass:string]:any;}

  constructor(
    public ts: TranslatorService,
    public cs: CommonService,
    public authService: AuthenticationService,
    public sharedData: SharedDataService,
    public events: Events,
    public MowadhafiService: MowadhafiService,
    private location: Location,
    public route: ActivatedRoute

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

  ionAlwaysEnter(){
    this.cs.startLoading();
    this.getTicketsByEmployee();
  }

  ngOnInit() {}

  goback() {
    this.location.back();

  }

  public openHRRequestPage() {
    this.cs.openHRRequestPage();
    // this.menu.toggle();
  }

  public openRequestDetailsPage(item) {
    this.cs.sharedService.setSharedData(item,'ticket-info')
    this.cs.openRequestDetailsPage();
    // this.menu.toggle();
  }


  getTicketsByEmployee() {
    const request = {
      EmployeeNumber: "",
      ItgPageSize: this.ticketCount,
      ItgPageNo: this.ticketPage
    };
    this.MowadhafiService.getTicketsByEmployee(request, () => { }, this.ts.trPK('general', 'retry')).subscribe((result) => {
      this.handlegetTicketsByEmployeeResult(result);

    })
  }

  handlegetTicketsByEmployeeResult(result){
    this.ticketsInfo = result.Mohemm_ITG_TicketsByEmployeeList;
    if(this.ticketsInfo.length > 0){
      this.ticketTotal=this.ticketsInfo[0].totalItemsCount;
    }
      this.ticketCount += 10;
  }

}
