import { Component, OnInit, Inject } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ApiService } from 'app/api.service';
import { DecimalPipe } from '@angular/common';


@Component({
  selector: 'app-orders-packing',
  templateUrl: './orders-packing.component.html',
  styleUrls: ['./orders-packing.component.scss']
})
export class OrdersPackingComponent implements OnInit {

  public packings: any = [];
  public another: any = [];

  constructor(private pn: DecimalPipe, private title: Title, public apiService: ApiService, public dialogRef: MatDialogRef<OrdersPackingComponent>, @Inject(MAT_DIALOG_DATA) public data: any) {
    this.apiService.getPacking(this.data.id).subscribe((data:any)=>{
      this.packings = data.data;
      this.another = data.another;
    })
  }

  ngOnInit() {

  }
  print(index:number) {
    let resource = this.packings[index];
    let destiny = resource.destiny.split("|");

    let params = `scrollbars=no,resizable=no,width=500,height=300,status=no,location=no,toolbar=no,menubar=no,titlebar=no, width=0,height=0,left=0,top=0`;
    var newWindow = window.open(null, 'printerzebra', params);
    let html = "<table width='450' cellspacing='0' cellpadding='0'>" + 
               "<tr><td colspan='4' style='height: 200px'>&nbsp;</td></tr>" +
               "<tr><td width='300'>"+resource.description+"</td><td width='40'>"+this.pn.transform(resource.grs, '1.2-2')+"</td><td width='40'>"+this.pn.transform(resource.thc, '1.2-2')+"</td><td widtH='40'>"+this.pn.transform(resource.cbd, '1.2-2')+"</td></tr>" +
               "<tr><td width='300'>&nbsp;</td><td width='120' colspan='3'>"+destiny[0]+"<br />"+destiny[1]+"</td></tr>" +
               "</table><script type='text/javascript'>window.print(); window.close();</script>";
    newWindow.document.write(html);

  }
  dismiss() {
    this.dialogRef.close();
  }

}
