import ISummary from '@/core/models/summary';
import { AbstractSelectComponent, ISelectItem } from '@/shared/abstractClasses';
import { UikitFieldComponent } from '@/uikit';
import { Component, inject, Input } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { Select } from 'primeng/select';
import { Observable } from 'rxjs';
import { AccountType, AccountTypeTranslates } from 'src/assets/constants';
import { CatalogsService } from '../../service';

@Component({
  selector: 'catalog-accountTypes-select',
  templateUrl: '../../template.html',
  imports: [UikitFieldComponent, Select, ReactiveFormsModule],
})
export class CatalogAccountTypeSelectComponent extends AbstractSelectComponent<
  ISummary,
  ISelectItem[]
> {
  @Input() override showClear: boolean = false;
  @Input() label: string = '';
  private readonly service = inject(CatalogsService);

  get preparedLabel() {
    return this.label || 'انتخاب نوع حساب';
  }

  ngOnInit() {
    this.getData();
  }

  getDataService() {
    return new Observable<ISelectItem[]>((observer) => {
      const accountTypes = [] as ISelectItem[];
      Object.entries(AccountType).forEach(([key, value]) => {
        accountTypes.push({
          id: value,
          name: AccountTypeTranslates[value],
        });
      });
      observer.next(accountTypes);
    });
  }
}
