import { Component, Input, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { City } from 'src/app/models/city';
import { SenorsPumpPriorityWharf } from 'src/app/models/senorsPumpPriorityWharf';
import { Wharf } from 'src/app/models/Wharf';
import { WerfFormFourService } from './werf-form-four.service';



@Component({
  selector: 'app-werf-form-four',
  templateUrl: './werf-form-four.component.html',
  styleUrls: ['./werf-form-four.component.css']
})
export class WerfFormFourComponent implements OnInit {
  wharf: Wharf = {
    id: 0,
    uuid: null,
    nameCode: '',
    cityID: 0,
    streetName: '',
    streetNumber: 0,
    startDate: '',
    endDate: '',
    wharfDepth: 0,
    city: null,
    flowRates: null,
    logs: null,
    pumps: null,
    sensors: null,
    webUserWharves: null
  };

  // city
  @Input() city: City = {
    id: 0,
    postalCode: 0,
    name: ''
  }

  // pump - sensor- status
  @Input() senorsPumpPriorityWharf: SenorsPumpPriorityWharf = {
    id: 0,
    pumpID: 0,
    sensorWithPriorities: null
  }

  cities$: Observable<City[]> = new Observable<City[]>();
  senorsPumpPriorityWharf$: Observable<SenorsPumpPriorityWharf[]> = new Observable<SenorsPumpPriorityWharf[]>();

  wharfId = 0;

  constructor(private werfFormFourService: WerfFormFourService,
    private route: ActivatedRoute,
    private router: Router) { }

  ngOnInit(): void {
    this.wharfId = parseInt(JSON.parse(this.route.snapshot.paramMap.get('wharfIid') || '{}'));
    if (this.wharfId != null) {
      this.werfFormFourService.getWharfById(+this.wharfId).subscribe(result => this.wharf= result);
    }

    this.cities$ = this.werfFormFourService.getCities();
  }

  back(){
    this.router.navigateByUrl('/admin/werf/form3/' + this.wharfId);
  }

  next(){
    this.router.navigateByUrl('/overzicht_werven' );
  }

  overzicht(){
    this.router.navigateByUrl('/overzicht_werven');
  }

}
