import {
  AfterViewInit,
  Component,
  Inject,
  OnInit,
  ViewChild,
} from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatTableDataSource } from '@angular/material/table';

@Component({
  selector: 'app-ver-dias-descanso',
  templateUrl: './ver-dias-descanso.component.html',
  styleUrls: ['./ver-dias-descanso.component.css'],
})
export class VerDiasDescansoComponent implements AfterViewInit {
  displayedColumns: string[] = ['dias_descanso_dia', 'dias_descanso_descansa'];

  dias_descanso_dia: any[] = this.data.item.DIASDESCANSO;
  dias_descanso_descansa: any[] = this.data.item.DIASDESCANSO;

  dataSource = new MatTableDataSource<any>(this.dias_descanso_dia);

  constructor(
    public dialogRef: MatDialogRef<any>,
    @Inject(MAT_DIALOG_DATA) public data: any
  ) {
    this.data.item.DIASDESCANSO = this.orderWeek();
  }

  ngAfterViewInit(): void {}

  formartWeek(semana: string) {
    switch (semana) {
      case 'Do':
        return 'Domingo';
      case 'Ju':
        return 'Jueves';
      case 'Lu':
        return 'Lunes';
      case 'Ma':
        return 'Martes';
      case 'Mi':
        return 'Miercoles';
      case 'Sa':
        return 'Sábado';
      case 'Vi':
        return 'Viernes';
      default:
        return semana;
    }
  }

  orderWeek(){
    let arr_week: any[] = []
    this.data.item.DIASDESCANSO.forEach((element:any) => {
      switch (element.dia) {
        case 'Do':
          element.id = 7;
          break;
        case 'Ju':
          element.id = 4;
          break;
        case 'Lu':
          element.id = 1;
          break;
        case 'Ma':
          element.id = 2;
          break;
        case 'Mi':
          element.id = 3;
          break;
        case 'Sa':
          element.id = 6;
          break;
        case 'Vi':
          element.id = 5;
          break;
      }
      arr_week.push( element )
    });

    arr_week.sort( (a,b) =>{
      return a.id - b.id;
    });
    

    return arr_week;    
  }
}
