import { DatePipe } from '@angular/common';
import {
  ChangeDetectionStrategy,
  Component,
  computed,
  input,
} from '@angular/core';
import { Receipt } from '@isa/oms/data-access';
import { ReceiptTypeTranslationPipe } from '@isa/oms/utils/translation';
import { ItemRowDataImports } from '@isa/ui/item-rows';

export type ReceiptInput = Pick<
  Receipt,
  'buyer' | 'shipping' | 'printedDate' | 'receiptType' | 'order'
>;

@Component({
  selector: 'oms-feature-return-details-order-group-data',
  templateUrl: './return-details-order-group-data.component.html',
  styleUrls: ['./return-details-order-group-data.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
  standalone: true,
  imports: [ItemRowDataImports, ReceiptTypeTranslationPipe, DatePipe],
})
export class ReturnDetailsOrderGroupDataComponent {
  receipt = input.required<ReceiptInput>();

  buyerName = computed(() => {
    const receipt = this.receipt();

    if (!receipt) {
      return '';
    }

    return [receipt.buyer?.firstName, receipt.buyer?.lastName]
      .filter(Boolean)
      .join(' ');
  });

  shippingName = computed(() => {
    const receipt = this.receipt();

    if (!receipt) {
      return '';
    }

    return [receipt.shipping?.firstName, receipt.shipping?.lastName]
      .filter(Boolean)
      .join(' ');
  });
}
