import { Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatTableDataSource } from '@angular/material/table';
import { ConfigOrderComponent } from '../config-order/config-order.component';
import { InfoOrderComponent } from '../info-order/info-order.component';

const DATA_EXAMPLE: Array<any> = [
  {
    codigoOrden: '000000001',
    proveedor: 'Soler & Palau México',
    precioTotal: '$79.99',
    fechaEmision: '10/11/2022 10:27:32',
    numeroUsuario: 'Jean Jairo Benitez Meza',
    despacho: 'Despacho de Observatorio',
    metodoPago: 'Sin asignación',
    proposito: 'Sin proposito'
  },
];

@Component({
  selector: 'app-group-order',
  templateUrl: './group-order.component.html',
  styleUrls: ['./group-order.component.css']
})
export class GroupOrderComponent implements OnInit {

  public displayedColumns: string[] = [
    'ITEM1',
    'ITEM2',
    'ITEM3',
    'ITEM4',
    'ITEM5',
    'ITEM6',
    'ITEM7',
    'ITEM8',
    'ITEM9',
  ];

  // ---- Loading Data ----
  public isLoading: boolean = false;
  public isLoadingForm: boolean = false;

  // ---- SmartPage ----
  public btnSmall: boolean = false;
  public card_size = 'card-size-normal mat-elevation-z8';


  // ---- Tabla ----
  public dataSource: Array<any>;

  constructor(
    public dialog: MatDialog,
  ) {
    this.dataSource = DATA_EXAMPLE;
  }

  ngOnInit(): void {
    this.onResize();
  }

  public openDialog(action: string, data: any = null) {
    if (action === 'VIEW') {
      const dialogRef = this.dialog.open(InfoOrderComponent, {
        width: '1000px',
        disableClose: true,
      });
    } else if (action === 'CONF') {
      const dialogRef = this.dialog.open(ConfigOrderComponent, {
        width: '400px',
        disableClose: true,
      });
    }
  }

  // Método para reajustar la pantalla
  public onResize() {
    if (window.innerWidth <= 1400) {
      this.btnSmall = true;
      this.card_size = 'card-size-small';
    } else if (window.innerWidth > 1400) {
      this.btnSmall = false;
      this.card_size = 'card-size-normal mat-elevation-z8';
    }
  }
}
