import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import {
  SlutredovisningResponseMainOccupationEducationDetails,
  SlutredovisningResponseMainOccupationOtherDetails,
  SlutredovisningResponseMainOccupationStillUnemployedDetails,
  SlutredovisningResponseMainOccupationWorkDetails,
} from '@msfa-models/api/slutredovisning.response.model';
import {
  educationLengthToString,
  educationLevelToString,
  MainOccupation,
  mainOccupationToString,
  Omfattning,
  omfattningToString,
  Slutredovisning,
} from '@msfa-models/slutredovisning.model';
import { capitalizeSentence } from '@msfa-utils/capitalize-sentence.util';

@Component({
  selector: 'msfa-slutredovisning-view-description-list',
  templateUrl: './slutredovisning-view-description-list.component.html',
  styleUrls: ['./slutredovisning-view-description-list.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SlutredovisningViewDescriptionListComponent {
  capitalizeSentence = capitalizeSentence;
  @Input() slutredovisning: Slutredovisning;

  get mainOccupationName(): string | null {
    return mainOccupationToString(this.slutredovisning?.mainOccupation?.type);
  }

  get education(): SlutredovisningResponseMainOccupationEducationDetails {
    return this.slutredovisning?.mainOccupation?.type === MainOccupation.Education
      ? this.slutredovisning.mainOccupation.education
      : undefined;
  }

  get work(): SlutredovisningResponseMainOccupationWorkDetails[] {
    return this.slutredovisning?.mainOccupation?.type === MainOccupation.Work
      ? this.slutredovisning.mainOccupation.work
      : undefined;
  }

  get stillUnemployed(): SlutredovisningResponseMainOccupationStillUnemployedDetails {
    return this.slutredovisning?.mainOccupation?.type === MainOccupation.StillUnemployed
      ? this.slutredovisning.mainOccupation.stillUnemployed
      : undefined;
  }

  get other(): SlutredovisningResponseMainOccupationOtherDetails {
    return this.slutredovisning?.mainOccupation?.type === MainOccupation.Other
      ? this.slutredovisning.mainOccupation.other
      : undefined;
  }

  get educationLevel(): string {
    return educationLevelToString(this.education.educationLevel);
  }
  get educationLength(): string {
    return educationLengthToString(this.education.educationLength);
  }
  omfattningToString(omfattning: Omfattning): string {
    return omfattningToString(omfattning);
  }
}
