import {
  ChangeDetectionStrategy,
  Component,
  computed,
  input,
} from '@angular/core';
import { ConfirmationListItemActionCardComponent } from './confirmation-list-item-action-card/confirmation-list-item-action-card.component';
import {
  ProductInfoComponent,
  DisplayOrderDestinationInfoComponent,
} from '@isa/checkout/shared/product-info';
import { DisplayOrderItemDTO } from '@generated/swagger/oms-api';
import { type OrderItemGroup, type Product } from '@isa/checkout/data-access';

@Component({
  selector: 'checkout-order-confirmation-item-list-item',
  templateUrl: './order-confirmation-item-list-item.component.html',
  styleUrls: ['./order-confirmation-item-list-item.component.css'],
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [
    ConfirmationListItemActionCardComponent,
    ProductInfoComponent,
    DisplayOrderDestinationInfoComponent,
  ],
})
export class OrderConfirmationItemListItemComponent {
  item = input.required<DisplayOrderItemDTO>();

  /**
   * The order item group containing the delivery type, destination, and other group metadata.
   * This now receives an OrderItemGroup which contains the necessary order information
   * (features, targetBranch, shippingAddress) required by the DisplayOrderDestinationInfoComponent.
   */
  order = input.required<OrderItemGroup>();

  productItem = computed<Product | undefined>(() => {
    return this.item()?.product;
  });

  points = computed(() => {
    const item = this.item();
    return item.loyalty?.value ?? 0;
  });
}
