import { Component, OnInit, DebugElement } from '@angular/core';
import { Pizza, ListPizzaGQL, PizzaChangedGQL } from 'src/generated/graphql';
import { Observable, race, combineLatest, concat, Subject } from 'rxjs';
import { map } from 'rxjs/operators';


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


  displayedColumns: string[] = [
    'id',
    'name',
  ];

  pizzas = new Subject<Pizza[]>();

  constructor(listPizza: ListPizzaGQL, pizzaChanged: PizzaChangedGQL) {

    listPizza
      .watch()
      .valueChanges
      .pipe(map(result => result.data.listPizza as Pizza[]))
      .subscribe((pizzas => this.pizzas.next(pizzas)));
    pizzaChanged.subscribe().pipe(map(event => event.data.pizzasChanged as Pizza[]))
      .subscribe((pizzas => this.pizzas.next(pizzas)));
  }

  ngOnInit(): void {
  }

}
