// import { CustomersSelectComponent } from '@/modules/customers/components/select/select.component';
// import { ICustomerResponse } from '@/modules/customers/models';
import { PriceMaskDirective } from '@/shared/directives';
import { UikitCounterComponent } from '@/uikit';
import { Component, computed, inject } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ButtonDirective } from 'primeng/button';
import { InplaceModule } from 'primeng/inplace';
import { InputNumber } from 'primeng/inputnumber';
import images from 'src/assets/images';
import { POSStore } from '../../store';
import { HeldOrdersComponent } from './held-orders.component';
import { POSOrderPriceInfoCardComponent } from './price-info-card.component';

@Component({
  selector: 'pos-order-card',
  templateUrl: './order-card.component.html',
  imports: [
    // CustomersSelectComponent,
    ButtonDirective,
    PriceMaskDirective,
    UikitCounterComponent,
    POSOrderPriceInfoCardComponent,
    FormsModule,
    InplaceModule,
    InputNumber,
    HeldOrdersComponent,
  ],
})
export class PosOrderCardComponent {
  private store = inject(POSStore);

  constructor() {
    // this.selectedCustomer.set(this.store.selectedCustomer());
  }

  posId = this.store.posId;

  placeholderImage = images.placeholders.default;

  inOrderProducts = computed(() => this.store.inOrderProducts());

  // selectedCustomer = signal<Maybe<ICustomerResponse>>(null);

  removeProductFromOrder(productId: number) {
    this.store.removeFromInOrderProducts(productId);
  }

  updateInOrderProductQuantity(productId: number, quantity: number) {
    this.store.updateInOrderProductQuantity(productId, quantity);
  }

  updateInOrderProductFee(productId: number, $event: Event, prevFee: number) {
    const unitPrice = $event.target
      ? parseFloat(($event.target as HTMLInputElement).ariaValueNow || prevFee.toString())
      : prevFee;

    this.store.updateInOrderProductFee(productId, unitPrice);
  }

  clearOrderList() {
    this.store.resetInOrderProducts();
  }

  // updateCustomer(customer: Maybe<ICustomerResponse>) {
  //   this.store.setSelectedCustomer(customer);
  // }

  submit() {
    this.store.submitOrder();
  }

  submitAndPay() {
    this.store.submitOrder();
  }
}
