// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
import { PageDataListComponent } from '@/shared/components/pageDataList/page-data-list.component';
import { partnerListConfig } from '@/shared/constants/list-configs';
import { Component, inject, TemplateRef, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { Avatar } from 'primeng/avatar';
import { GuildFormComponent } from '../components/form.component';
import { superAdminPartnersNamedRoutes } from '../constants';
import { IPartnerResponse } from '../models';
import { PartnersService } from '../services/main.service';

@Component({
  selector: 'app-users',
  templateUrl: './list.component.html',
  imports: [PageDataListComponent, GuildFormComponent, Avatar],
})
export class PartnersComponent extends AbstractList<IPartnerResponse> {
  private readonly service = inject(PartnersService);
  private readonly router = inject(Router);

  @ViewChild('name', { static: true }) name!: TemplateRef<any>;
  @ViewChild('licensesStatus', { static: true }) licensesStatus!: TemplateRef<any>;
  @ViewChild('accountQuotaStatus', { static: true }) accountQuotaStatus!: TemplateRef<any>;
  @ViewChild('licensesRenewStatus', { static: true }) licensesRenewStatus!: TemplateRef<any>;

  override setColumns(): void {
    this.columns = partnerListConfig.columns.map((col) => {
      if (col.field === 'name') return { ...col, customDataModel: this.name };
      if (col.field === 'licenses') return { ...col, customDataModel: this.licensesStatus };
      if (col.field === 'account_quota')
        return { ...col, customDataModel: this.accountQuotaStatus };
      if (col.field === 'license_renew')
        return { ...col, customDataModel: this.licensesRenewStatus };
      return col;
    });
  }

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

  toSinglePage(partner: IPartnerResponse) {
    this.router.navigateByUrl(superAdminPartnersNamedRoutes.partner.meta.pagePath!(partner.id));
  }
}
