import { ChangeDetectionStrategy, Component } from '@angular/core';
import { DeltagareCompact, DeltagareCompactData } from '@msfa-models/deltagare.model';
import { Sort } from '@msfa-models/sort.model';
import { DeltagareService } from '@msfa-services/api/deltagare.service';
import { Observable } from 'rxjs';

@Component({
  selector: 'msfa-deltagare',
  templateUrl: './deltagare.component.html',
  styleUrls: ['./deltagare.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DeltagareComponent {
  allDeltagareData$: Observable<DeltagareCompactData> = this.deltagareService.allDeltagareData$;
  sort$: Observable<Sort<keyof DeltagareCompact>> = this.deltagareService.sort$;
  onlyMyDeltagare$: Observable<boolean> = this.deltagareService.onlyMyDeltagare$;

  constructor(private deltagareService: DeltagareService) {}

  handleDeltagareSort(key: keyof DeltagareCompact): void {
    this.deltagareService.setSort(key);
  }

  setOnlyMyDeltagare(checked: boolean): void {
    this.deltagareService.setOnlyMyDeltagare(checked);
  }

  setNewPage(page: number): void {
    this.deltagareService.setPage(page);
  }
}
