import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ValueTupleOfStringAndIntegerAndIntegerAndNullableIntegerAndString } from '@swagger/remi';

@Component({
  selector: 'page-required-capacities',
  templateUrl: 'required-capacities.component.html',
  styleUrls: ['required-capacities.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RequiredCapacitiesComponent {
  @Input()
  requiredCapacities: ValueTupleOfStringAndIntegerAndIntegerAndNullableIntegerAndString[];

  get capacity() {
    return this.requiredCapacities?.find((_) => true)?.item3 || 0;
  }

  get maxCapacity() {
    return Math.max(this.capacity, this.requiredCapacities?.find((_) => true)?.item2);
  }

  get capacityPercentage() {
    if (this.maxCapacity > 0) {
      return (this.capacity / this.maxCapacity) * 100;
    }
    return 0;
  }

  get staple() {
    if (this.requiredCapacities?.length > 0) {
      return this.requiredCapacities[1].item3;
    }
    return 0;
  }

  get maxStaple() {
    if (this.requiredCapacities?.length > 0) {
      return Math.max(this.staple, this.requiredCapacities[1].item2);
    }
    return 0;
  }

  get staplePercentage() {
    if (this.maxStaple > 0) {
      return (this.staple / this.maxStaple) * 100;
    }
    return 0;
  }

  constructor() {}
}
