import ISummary from '@/core/models/summary';
import { AbstractSelectComponent, ISelectItem } from '@/shared/abstractClasses';
import { UikitFieldComponent } from '@/uikit';
import { Component, Input } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { Select } from 'primeng/select';
import { Observable } from 'rxjs';
import {
  BusinessRole,
  businessRoleTranslate,
  ComplexRole,
  complexRoleTranslate,
  PartnerRole,
  partnerRoleTranslate,
  POSRole,
  posRoleTranslate,
  ProviderRole,
  providerRoleTranslate,
} from 'src/assets/constants';

@Component({
  selector: 'catalog-roleTypes-select',
  templateUrl: '../../template.html',
  imports: [UikitFieldComponent, Select, ReactiveFormsModule],
})
export class CatalogRoleTypeSelectComponent extends AbstractSelectComponent<
  ISummary,
  ISelectItem[]
> {
  @Input() override showClear: boolean = false;
  @Input() label: string = '';
  @Input({ required: true }) type!: 'PARTNER' | 'PROVIDER' | 'BUSINESS' | 'COMPLEX' | 'POS';

  get preparedLabel() {
    return this.label || 'انتخاب سطح دسترسی';
  }

  ngOnInit() {
    this.getData();
  }

  getDataService() {
    return new Observable<ISelectItem[]>((observer) => {
      const roleTypes = [] as ISelectItem[];
      switch (this.type) {
        case 'PARTNER':
          Object.values(PartnerRole).forEach((value) => {
            roleTypes.push({
              id: value,
              name: partnerRoleTranslate[value],
            });
          });
          break;
        case 'PROVIDER':
          Object.values(ProviderRole).forEach((value) => {
            roleTypes.push({
              id: value,
              name: providerRoleTranslate[value],
            });
          });
          break;
        case 'BUSINESS':
          Object.values(BusinessRole).forEach((value) => {
            roleTypes.push({
              id: value,
              name: businessRoleTranslate[value],
            });
          });
          break;
        case 'COMPLEX':
          Object.values(ComplexRole).forEach((value) => {
            roleTypes.push({
              id: value,
              name: complexRoleTranslate[value],
            });
          });
          break;
        case 'POS':
          Object.values(POSRole).forEach((value) => {
            roleTypes.push({
              id: value,
              name: posRoleTranslate[value],
            });
          });
          break;
      }

      observer.next(roleTypes);
    });
  }
}
