import { Component, Input, OnChanges } from '@angular/core';
import { INestedFilter } from '@iqser/common-ui/lib/filtering';
import { TranslateService } from '@ngx-translate/core';

@Component({
    selector: 'redaction-type-filter',
    templateUrl: './type-filter.component.html',
    styleUrls: ['./type-filter.component.scss'],
})
export class TypeFilterComponent implements OnChanges {
    private _needsAnalysisKeys: string[] = ['remove-only-here', 'analysis'];
    @Input() filter: INestedFilter;
    @Input({ required: true }) dossierTemplateId: string;
    @Input() dossierId: string;
    label: string;

    constructor(private readonly _translateService: TranslateService) {}

    ngOnChanges(): void {
        this.label =
            this.filter.metadata?.shortLabel === ''
                ? ''
                : this.filter.id === 'none'
                ? '-'
                : this._needsAnalysisKeys.includes(this.filter.id)
                ? 'A'
                : this.filter.skipTranslation
                ? this.filter.label.charAt(0)
                : this._translateService.instant(this.filter.label).charAt(0);
    }
}
