import {
  ChangeDetectionStrategy,
  Component,
  computed,
  input,
} from '@angular/core';
import { ProductImageDirective } from '@isa/shared/product-image';
import { ProductRouterLinkDirective } from '@isa/shared/product-router-link';
import { RewardSelectionInputsComponent } from './reward-selection-inputs/reward-selection-inputs.component';
import {
  hasOrderTypeFeature,
  RewardSelectionItem,
} from '@isa/checkout/data-access';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { isaOtherInfo } from '@isa/icons';

@Component({
  selector: 'lib-reward-selection-item',
  templateUrl: './reward-selection-item.component.html',
  styleUrl: './reward-selection-item.component.css',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [
    ProductImageDirective,
    ProductRouterLinkDirective,
    RewardSelectionInputsComponent,
    NgIcon,
  ],
  providers: [provideIcons({ isaOtherInfo })],
})
export class RewardSelectionItemComponent {
  rewardSelectionItem = input.required<RewardSelectionItem>();

  inStock = computed(
    () => this.rewardSelectionItem().item?.availability?.inStock ?? 0,
  );

  isAbholung = computed(() =>
    hasOrderTypeFeature(this.rewardSelectionItem()?.item?.features, [
      'Abholung',
    ]),
  );

  showLowStockMessage = computed(() => {
    return this.isAbholung() && this.inStock() < 2;
  });
}
