// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
import {
  IColumn,
  PageDataListComponent,
} from '@/shared/components/pageDataList/page-data-list.component';
import { Component, inject, Input } from '@angular/core';
import { Router } from '@angular/router';
import { consumerCustomerSaleInvoicesNamedRoutes } from '../../constants/routes/saleInvoices';
import { ICustomerSaleInvoicesResponse } from '../../models/saleInvoices.io';
import { CustomerSaleInvoicesService } from '../../services/saleInvoices.service';

@Component({
  selector: 'consumer-customer-saleInvoice-list',
  templateUrl: './list.component.html',
  imports: [PageDataListComponent],
})
export class ConsumerCustomerSaleInvoiceListComponent extends AbstractList<ICustomerSaleInvoicesResponse> {
  @Input({ required: true }) customerId!: string;
  @Input() fullHeight?: boolean;
  @Input() header: IColumn[] = [
    { field: 'code', header: 'کد رهگیری' },
    {
      field: 'total_amount',
      header: 'قیمت نهایی',
      type: 'price',
    },
    {
      field: 'pos',
      header: 'پایانه',
      customDataModel(item: ICustomerSaleInvoicesResponse) {
        return `${item.pos.complex.business_activity.name}، شعبه ${item.pos.complex.name}، پایانه فروش ${item.pos.name}`;
      },
    },
    {
      field: 'account',
      header: 'ایجاد شده توسط',
      type: 'nested',
      nestedOption: { path: 'account.account.username' },
    },
    {
      field: 'invoice_date',
      header: 'تاریخ فاکتور',
      type: 'date',
    },
    {
      field: 'created_at',
      header: 'تاریخ ایجاد',
      type: 'date',
    },
  ];

  private readonly service = inject(CustomerSaleInvoicesService);
  private readonly router = inject(Router);

  override setColumns(): void {
    this.columns = this.header;
  }

  override getDataRequest() {
    return this.service.getAll(this.customerId);
  }

  toSinglePage(item: ICustomerSaleInvoicesResponse) {
    this.router.navigateByUrl(
      consumerCustomerSaleInvoicesNamedRoutes.saleInvoice.meta.pagePath!(this.customerId, item.id),
    );
  }
}
