import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { Observable } from 'rxjs';
import { TabSelectionOptions, TabSelectionOption } from '@libs/ui/lib/tab-selection';
import { RemissionService } from '@isa/remission';
import { RemissionTabsFilterService } from '../../../services';

@Component({
  selector: 'app-remission-suppliers-filter',
  templateUrl: 'suppliers-filter.component.html',
  styleUrls: ['./suppliers-filter.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RemissionSuppliersFilterComponent implements OnInit {
  supplierTabs$: Observable<TabSelectionOptions>;

  constructor(private remissionService: RemissionService, private filterService: RemissionTabsFilterService) {}

  ngOnInit() {
    this.initTabOptions();
  }

  initTabOptions() {
    this.supplierTabs$ = this.filterService.getSupplierTabs(this.remissionService.getRemissionTargets());
  }

  selectSupplier(selectedSupplier: TabSelectionOption) {
    this.filterService.setActiveSupplier(selectedSupplier.name);
  }
}
