import { Component, OnInit, Inject } from '@angular/core';
import { ContactService } from '../../../contact.service';
import { Router } from '@angular/router';
import { MdDialogRef, MD_DIALOG_DATA } from '@angular/material';

@Component({
  selector: 'app-expenselist',
  templateUrl: './expenselist.component.html',
  styleUrls: ['./expenselist.component.scss']
})
export class ExpenselistComponent implements OnInit {
  expenseObject=[];
  Load : boolean = false;
  trip_id: any;
  expenseArr: any;
  constructor(private contactService: ContactService,private router: Router,public dialogRef: MdDialogRef<ExpenselistComponent>,
    @Inject(MD_DIALOG_DATA) public data: any) { 
      console.log(data);
      this.trip_id = data._id;
    }

  ngOnInit() {
    this.Load  = true;
    this.expenseArr = [];
    this.contactService.getExpense(this.trip_id).subscribe(res=>{
      this.Load= false;
      console.log("response=>",res);
     var eArr = res;
      if(eArr.length == 0){

      }else{
        this.expenseArr = res;
      }

    },err=>{
      this.Load= false;
    })
  }

  delete(listObj){
    this.contactService.deleteExpense(listObj._id).subscribe(res=>{
      console.log(res);
      this.ngOnInit();
    })

  }

  cancel(){
    this.dialogRef.close('cancel');
  }

}
