import { Component, OnInit,Inject } from '@angular/core';
import {MdDialog, MdDialogRef, MD_DIALOG_DATA} from '@angular/material';
import {Device} from '../../device';
import {ContactService} from '../../contact.service';
import { FlashMessagesService } from 'angular2-flash-messages';
import { SidebarComponent } from '../../sidebar/sidebar.component';

@Component({
  selector: 'app-share-user',
  templateUrl: './share-user.component.html',
  styleUrls: ['./share-user.component.scss'],
  providers: [ContactService,SidebarComponent]
})
export class ShareUserComponent implements OnInit {
//shrdeviceOwner
d :any;
dname:any;
did :any;
devv:any;
deleteshare(uid){

  this.contactService.deldevshr( this.d,uid)
  .subscribe(
  
     data => {

      this.devv = data 
      window.localStorage['DataUpdate'] = 'True'
      this.sidebar.sidebarData()
      this.onNoClick("OKK")
    });
   
}
  constructor(public dialogRef: MdDialogRef<ShareUserComponent>,
    @Inject(MD_DIALOG_DATA) public data: any,private contactService: ContactService,private _flashMessagesService: FlashMessagesService,private sidebar: SidebarComponent) {
       this.d =data.name;
       this.dname = data.dname;
       this.did = data.did;
     }
    onNoClick(a): void {
      console.log(a);
     this.dialogRef.close(a);
    }
    devicess:any;
    final:any;
    foods = []
  ngOnInit() {


    this.contactService.shrdeviceOwner(this.d).subscribe(
      
      data => {
        this.devicess = data 
      
        for(let p=0;p<this.devicess.length;p++){
          this.devicess[p];
         let fs =  this.devicess[p].first_name;
         let ls =  this.devicess[p].last_name;
         let na = fs + " " + ls;
         let xz ={
           "name" :  na,
           "userid" : this.devicess[p]._id
         }
         this.foods.push(xz);
        }

      }, (err: any) => {; 
        console.log(err);
      if(err.status !=   200)
      {
     /*   this._flashMessagesService.show( "This Device is Not Shared to anyOne", { cssClass: 'alert-danger', timeout: 1000 }
      );
       */
      this.onNoClick("No_Dev")

      }});

  }

}
