import {
  AfterContentInit, Component, Input,
  OnInit
} from '@angular/core';
import { select, Store} from '@ngrx/store';
import { ActivatedRoute } from '@angular/router';
import { Probe, ProbeHost } from '@overflow/commons-typescript/model/probe';

import { AuthSelector } from '@overflow/member/store';
import { Domain } from '@overflow/commons-typescript/model/domain';
import * as ProbeEntityStore from '@overflow/probe/store/entity/probe';
import {Observable} from 'rxjs';
import { ProbeEntitySelector } from '@overflow/probe/store';

@Component({
  selector: 'of-discovery-container',
  templateUrl: './discovery-container.component.html',
})
export class DiscoveryContainerComponent implements OnInit, AfterContentInit {

  // probe select ?
  // get probe list for server
  // discovery start
  // discovery stop
  // get service list
  @Input() hostID;

  probeHosts$: Observable<Probe[]>;
  selectProbes?: Probe[];

  constructor(
    private activatedRoute: ActivatedRoute,
    private store: Store<ProbeEntityStore.State>
  ) {
      this.probeHosts$ = store.pipe(select(ProbeEntitySelector.selectAll));

  }

  ngOnInit() {
    this.store.select(AuthSelector.select('domain')).subscribe(
      (domain: Domain) => {
        this.store.dispatch(new ProbeEntityStore.ReadAllByDomainID(domain.id));
      },
      (error) => {
        console.log(error);
      }
    );
  }

  ngAfterContentInit() {
  }

}
