import { Component, Inject, Input, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';

import {
  MdDialog,
  MdDialogRef,
  MD_DIALOG_DATA,
  MdTabChangeEvent,
} from "@angular/material";
import { ContactService } from '../contact.service';

@Component({
  selector: 'app-gprs-commnd-table-popup',
  templateUrl: './gprs-commnd-table-popup.component.html',
  styleUrls: ['./gprs-commnd-table-popup.component.scss']
})
export class GprsCommndTablePopupComponent implements OnInit {

  injectedData: any;
  useridd: any;
  errFlag: boolean = false;
  errmsg: any = '';
  command: any = '';
  action: any;
  device_type: any;
  imei:any;
  ip:any;
  port:any;
  protocol_type:any;
  constructor(public dialogRef: MdDialogRef<GprsCommndTablePopupComponent>,
    @Inject(MD_DIALOG_DATA) public data: any, private contactService: ContactService) {

    this.injectedData = data;
    console.log('raw data dialog=>',this.injectedData)

  }

  ngOnInit() {

    this.imei = this.injectedData.deviceObject.imei;
  this.deviceCQ(this.imei);
  }
  dcqData = [];
  deviceCQ(imeiObj) {

    var imei = imeiObj.Device_ID ? imeiObj.Device_ID : imeiObj;
    this.dcqData = [];
    this.contactService.deviceCmdQueue(imei).subscribe(
      (resp) => {
        var tempLog = resp;
        this.dcqData = resp;
      },
      (err) => {
        this.dcqData = [];
      }
    );
  }
  closeModal(): void {
    this.dialogRef.close();
  }

}
