import { Component, OnInit } from '@angular/core';
import { MatTableDataSource } from '@angular/material/table';

@Component({
  selector: 'app-maintenance-simulation',
  templateUrl: './maintenance-simulation.component.html',
  styleUrls: ['./maintenance-simulation.component.css']
})
export class MaintenanceSimulationComponent implements OnInit {
  public btnSmall: boolean;
  public txtBuscador:string;

  dataSource?: MatTableDataSource<any>;

  isLoading: boolean;
  hasError: boolean;
  errorStr: string; 

  constructor() { 
    this.btnSmall = window.innerWidth <= 1405;
    this.txtBuscador = '';
    this.dataSource = new MatTableDataSource();
    this.isLoading = true;
    this.hasError = false;
    this.errorStr = "";
  }

  ngOnInit(): void {
  }

  public onResize():void {
    this.btnSmall = window.innerWidth <= 1405;
  }

  applyFilter(event: any, type: string){
    let filterValue:string;
    if (type == 'INP') {
      filterValue = (event.target as HTMLInputElement).value;
    }else{
      this.txtBuscador = event;
      filterValue = event;
    }
    this.dataSource!.filter = filterValue.trim().toLowerCase();

    if(this.dataSource?.paginator){
      this.dataSource.paginator.firstPage();
    }
  }
}
