import { AfterViewInit, ChangeDetectionStrategy, Component, EventEmitter, OnChanges, OnDestroy, OnInit, Output, ViewChild, input, model, } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { Subscription } from 'rxjs'; import { OptionDirective, SelectBoxComponent, unsubscribe } from '@deepkit/desktop-ui'; import { TypeEnum } from '@deepkit/type'; import { DataStructure } from '../../store'; import { TypeDecoration } from '../../utils.js'; @Component({ template: ` @for (kv of keyValues; track kv) { {{ kv.label }} } `, changeDetection: ChangeDetectionStrategy.Eager, imports: [SelectBoxComponent, FormsModule, OptionDirective], }) export class EnumInputComponent implements OnChanges, OnInit, AfterViewInit, OnDestroy { model = model.required(); decoration = input(); type = input.required(); keyValues: { value: any; label: string | number | undefined | null }[] = []; @Output() keyDown = new EventEmitter(); @ViewChild('select') select?: SelectBoxComponent; @unsubscribe() protected dropdownSub?: Subscription; ngOnDestroy() {} ngOnInit() { this.load(); } ngOnChanges() { this.load(); } ngAfterViewInit() { this.select?.open(); } load() { this.type().enum; for (const [label, value] of Object.entries(this.type().enum)) { this.keyValues.push({ value, label }); } } }