import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Avrop, AvropCompactData } from '@msfa-models/avrop.model';
import { Handledare } from '@msfa-models/handledare.model';
import { MultiselectFilterOption } from '@msfa-models/multiselect-filter-option';
import { AvropService } from '@msfa-services/avrop.service';
import { Observable } from 'rxjs';

@Component({
  selector: 'msfa-avrop',
  templateUrl: './avrop.component.html',
  styleUrls: ['./avrop.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AvropComponent {
  readonly totalAmountOfSteps = 3;
  currentStep$: Observable<number> = this.avropService.currentStep$;

  error$: Observable<string> = this.avropService.error$;
  filteredUtforandeVerksamheter$: Observable<MultiselectFilterOption[]> = this.avropService
    .filteredUtforandeVerksamheter$;
  avropData$: Observable<AvropCompactData> = this.avropService.avropData$;
  selectedAvrop$: Observable<Avrop[]> = this.avropService.selectedAvrop$;
  availableHandledare$: Observable<Handledare[]> = this.avropService.availableHandledare$;
  selectedHandledare$: Observable<Handledare> = this.avropService.selectedHandledare$;
  avropIsLocked$: Observable<boolean> = this.avropService.avropIsLocked$;
  handledareConfirmed$: Observable<boolean> = this.avropService.handledareIsConfirmed$;
  avropIsSubmitted$: Observable<boolean> = this.avropService.avropIsSubmitted$;

  constructor(private avropService: AvropService) {}

  updateSelectedAvrop(deltagareList: Avrop[]): void {
    this.avropService.setSelectedAvrop(deltagareList);
  }

  lockSelectedAvrop(): void {
    this.avropService.lockSelectedAvrop();
  }

  unlockSelectedAvrop(): void {
    this.avropService.unlockSelectedAvrop();
  }

  confirmHandledare(): void {
    this.avropService.confirmHandledare();
  }

  unconfirmHandledare(): void {
    this.avropService.unconfirmHandledare();
  }

  async save(): Promise<void> {
    return this.avropService.save();
  }

  changeHandledare(handledareId: string): void {
    this.avropService.assignHandledare(handledareId);
  }

  returnToStep1(): void {
    this.avropService.goToStep1();
  }

  resetError(): void {
    this.avropService.resetError();
  }

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