import { Component, Input, OnChanges } from '@angular/core';
import { SuperTypes } from '@red/domain';
import { DefaultColorsService } from '@services/entity-services/default-colors.service';
import { TranslateService } from '@ngx-translate/core';
import { INestedFilter } from '@iqser/common-ui/lib/filtering';

@Component({
    selector: 'redaction-type-filter [dossierTemplateId]',
    templateUrl: './type-filter.component.html',
    styleUrls: ['./type-filter.component.scss'],
})
export class TypeFilterComponent implements OnChanges {
    private _suggestionsKeys: string[] = [
        SuperTypes.SuggestionRemove,
        SuperTypes.SuggestionForceRedaction,
        SuperTypes.SuggestionAdd,
        SuperTypes.SuggestionRemoveDictionary,
        SuperTypes.SuggestionAddDictionary,
        SuperTypes.DeclinedSuggestion,
        'suggestion',
    ];
    private _needsAnalysisKeys: string[] = ['remove-only-here', 'analysis'];
    @Input() filter: INestedFilter;
    @Input() dossierTemplateId: string;
    @Input() dossierId: string;
    label: string;

    constructor(private readonly _defaultColorsService: DefaultColorsService, private readonly _translateService: TranslateService) {}

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