import { Component, OnInit } from '@angular/core';
import { MatTableDataSource } from '@angular/material/table';
import { ResourcesService } from '../../../../services/resources.service';
import { ActivatedRoute, Router } from '@angular/router';
import { EncService } from '../../../../services/enc.service';

@Component({
    selector: 'app-hourly-rate',
    templateUrl: './hourly-rate.component.html',
    styleUrl: './hourly-rate.component.css',
    standalone: false
})
export class HourlyRateComponent implements OnInit {
  public dataSource: MatTableDataSource<any>;
  public displayedColumns: Array<string>;
  public isLoading: boolean;
  public isLoadingForm: boolean;
  public idEmployee: string;

  constructor(
    public resourcesService: ResourcesService,
    private _activatedRouter: ActivatedRoute,
    private _encService: EncService,
    private _router: Router,
  ) {
    this.dataSource = new MatTableDataSource<any>();
    this.displayedColumns = ['NUMERO_ORDEN','TIPO','FECHA_INICIO','FECHA_FIN','HORAS','COSTO'];
    this.isLoading = false;
    this.isLoadingForm = false;
    this.idEmployee = '';
  }
  
  async ngOnInit() {
    this.getDataEmployee();
  }

  private async getDataEmployee() {
    let encEmployee = this._activatedRouter.snapshot.paramMap.get('idEmployee');
    if (encEmployee === null) {
      this.resourcesService.openSnackBar(`Ocurrío un error al obtener el ID del empleado.`);
      this._router.navigate(['/sam/GPRS/GEPE/GEPE']);
      return;
    }    
    this.idEmployee = await this._encService.decrypt(encEmployee);
  }
}
