import { Maybe } from '@/core';
import { IPosHeldOrderResponse } from '@/modules/pos/models';
import { Component, inject, signal } from '@angular/core';
import { PosService } from '../../services/main.service';
import { HeldOrderItemComponent } from './held-order-item.component';

@Component({
  selector: 'app-held-orders',
  templateUrl: './held-orders.component.html',
  imports: [HeldOrderItemComponent],
})
export class HeldOrdersComponent {
  private readonly service = inject(PosService);

  heldOrders = signal<Maybe<IPosHeldOrderResponse[]>>(null);
  loading = signal<boolean>(false);

  ngOnInit() {
    this.getHeldOrders();
  }

  getHeldOrders() {
    this.loading.set(true);
    // this.service.getHeldOrders().subscribe({
    //   next: (res) => {
    //     this.heldOrders.set(res.data);
    //     this.loading.set(false);
    //   },
    //   error: () => {
    //     this.loading.set(false);
    //   },
    // });
  }

  removeHeldOrder(orderId: number) {
    const currentOrders = this.heldOrders() || [];
    this.heldOrders.set(currentOrders.filter((order) => order.id !== orderId));
  }
}
