import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { DeltagareHandelserApiService } from '@msfa-services/api/deltagare-handelser-api.service';
import { DeltagareHandelse } from '@msfa-models/deltagare-handelse.model';
import { Observable } from 'rxjs';
import { IconType } from '@msfa-enums/icon-type.enum';
import { DeltagareCompact } from '@msfa-models/deltagare.model';

@Component({
  selector: 'msfa-deltagare-list-handelser-dialog',
  templateUrl: './deltagare-list-handelser-dialog.component.html',
  styleUrls: ['./deltagare-list-handelser-dialog.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DeltagareListHandelserDialogComponent implements OnInit {
  @Input() deltagare: DeltagareCompact;
  iconType = IconType;
  deltagareHandelser$: Observable<DeltagareHandelse[]>;

  constructor(private deltagareHandelserApiService: DeltagareHandelserApiService) {}

  ngOnInit(): void {
    if (this.deltagare) {
      this.deltagareHandelser$ = this.deltagareHandelserApiService.fetchDeltagareHandelser(
        this.deltagare.genomforandeReferens
      );
    }
  }
}
