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

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

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

  ngOnInit() {
    this.initTabOptions();
  }

  initTabOptions() {
    this.sourceTabs$ = this.filterService.getSourcesTabs(this.remissionService.getRemissionSources());
  }

  selectSource(selectedSource: TabSelectionOption) {
    this.filterService.setActiveSource(selectedSource.name);
  }
}
