import { SharedSaleInvoiceSingleViewComponent } from '@/shared/components/invoices/sale-invoice-single-view.component';
import pageParamsUtils from '@/utils/page-params.utils';
import { Component, computed, inject, signal } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { posSaleInvoicesNamedRoutes } from '../constants';
import { PosSaleInvoiceStore } from '../store/main.store';

@Component({
  selector: 'pos-saleInvoice',
  templateUrl: './single.component.html',
  imports: [SharedSaleInvoiceSingleViewComponent],
})
export class PosSaleInvoiceComponent {
  private readonly route = inject(ActivatedRoute);
  private readonly store = inject(PosSaleInvoiceStore);

  pageParams = computed(() => pageParamsUtils(this.route));
  invoiceId = signal<string>(this.pageParams()['invoiceId']);

  readonly invoice = computed(() => this.store.entity());
  readonly loading = computed(() => this.store.loading());

  readonly backRoute = computed(() => posSaleInvoicesNamedRoutes.saleInvoices.meta.pagePath!());

  ngOnInit() {
    this.store.getData(this.invoiceId());
  }
}
