import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { workflowFileStatusTranslations } from '@translations/file-status-translations';
import { ISearchListItem } from '@red/domain';
import { escapeHtml } from '@iqser/common-ui/lib/utils';
import { getDossierRouterLink } from '@utils/router-links';

@Component({
    selector: 'redaction-search-item-template',
    templateUrl: './search-item-template.component.html',
    styleUrls: ['./search-item-template.component.scss'],
})
export class SearchItemTemplateComponent implements OnChanges {
    @Input() item: ISearchListItem;
    @Output() readonly mustContain = new EventEmitter<string>();
    readonly fileStatusTranslations = workflowFileStatusTranslations;

    routerLink: string;

    sanitize(value: string) {
        return escapeHtml(value, {
            ignoreTags: ['em'],
        });
    }

    ngOnChanges(changes: SimpleChanges): void {
        if (changes.item) {
            this.routerLink = getDossierRouterLink(this.item.dossierTemplateId, this.item.dossierId, this.item.archived);
        } else {
            this.routerLink = undefined;
        }
    }
}
