// 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 { ConsumerBusinessActivityFormComponent } from '../components/form-dialog.component';
import { consumerCustomersNamedRoutes } from '../constants';
import { ICustomerResponse } from '../models';
import { CustomersService } from '../services/main.service';

@Component({
  selector: 'consumer-customer-list',
  templateUrl: './list.component.html',
  imports: [PageDataListComponent, ConsumerBusinessActivityFormComponent],
})
export class ConsumerCustomerListComponent extends AbstractList<ICustomerResponse> {
  @Input() fullHeight?: boolean;
  @Input() header: IColumn[] = [
    { field: 'id', header: 'شناسه', type: 'id' },
    {
      field: 'type',
      header: 'نوع مشتری',
      customDataModel(item) {
        return item.type === 'LEGAL' ? 'حقوقی' : 'حقیقی';
      },
    },

    {
      field: 'name',
      header: 'عنوان',
      customDataModel(item: ICustomerResponse) {
        if (item.type === 'LEGAL') {
          return item.legal!.company_name;
        }
        return `${item.individual!.first_name} ${item.individual!.last_name}`;
      },
    },
    {
      field: 'economic_code',
      header: 'کد اقتصادی',
      customDataModel(item: ICustomerResponse) {
        if (item.type === 'LEGAL') {
          return item.legal!.economic_code;
        }
        return item.individual!.economic_code;
      },
    },
    {
      field: 'created_at',
      header: 'تاریخ ایجاد',
      type: 'date',
    },
  ];

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

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

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

  toSinglePage(item: ICustomerResponse) {
    this.router.navigateByUrl(consumerCustomersNamedRoutes.customer.meta.pagePath!(item.id));
  }
}
