import { ChangeDetectionStrategy, Component, effect, inject, input, output } from '@angular/core';

import { ButtonComponent } from '../../../../shared/components/button/button.component';
import { QrPaymentContentComponent } from './components/payment-methods/qr-payment-content.component';
import { TelepagosPaymentContentComponent } from './components/payment-methods/telepagos-payment-content.component';
import { TransferPaymentContentComponent } from './components/payment-methods/transfer-payment-content.component';
import { CheckoutPaymentFacade } from './checkout-payment.facade';
import { PaymentMethod, TransferField } from './checkout-page.models';

@Component({
  selector: 'app-checkout-payment-step',
  standalone: true,
  imports: [
    ButtonComponent,
    QrPaymentContentComponent,
    TelepagosPaymentContentComponent,
    TransferPaymentContentComponent
  ],
  templateUrl: './checkout-payment-step.component.html',
  styleUrl: './checkout-payment-step.component.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
  providers: [CheckoutPaymentFacade]
})
export class CheckoutPaymentStepComponent {
  protected readonly payment = inject(CheckoutPaymentFacade);
  readonly purchaseId = input<number | null>(null);

  readonly cancelStep = output<void>();
  readonly complete = output<void>();

  constructor() {
    effect(() => this.payment.setPurchaseId(this.purchaseId()));
  }

  protected selectPaymentMethod(method: PaymentMethod): void {
    void this.payment.selectMethod(method);
  }

  protected requestCopy(field: TransferField, value: string): void {
    void this.payment.copyTransferValue(field, value);
  }

  protected requestTransfer(dni: string): void {
    void this.payment.requestTransferData(dni);
  }
}
