import { Component, HostBinding, inject, Input, OnChanges } from '@angular/core';
import { AnnotationWrapper } from '@models/file/annotation.wrapper';
import { PdfProxyService } from '../../services/pdf-proxy.service';
import { ActionsHelpModeKeys } from '../../utils/constants';
import { ListItem } from '@models/file/list-item';
import { MultiSelectService } from '../../services/multi-select.service';

@Component({
    selector: 'redaction-annotation-wrapper',
    templateUrl: './annotation-wrapper.component.html',
    styleUrls: ['./annotation-wrapper.component.scss'],
})
export class AnnotationWrapperComponent implements OnChanges {
    @Input({ required: true }) annotation!: ListItem<AnnotationWrapper>;

    @HostBinding('attr.annotation-id') annotationId: string;
    @HostBinding('class.active') active = false;
    actionsHelpModeKey?: string;
    protected readonly _pdfProxyService = inject(PdfProxyService);
    protected readonly _multiSelectService = inject(MultiSelectService);

    ngOnChanges() {
        this.annotationId = this.annotation.item.id;
        this.active = this.annotation.isSelected;
        this.actionsHelpModeKey = this.#getActionsHelpModeKey();
    }

    #getActionsHelpModeKey(): string {
        const type = this.annotation.item.typeLabel?.split('.')[1];
        const typeValue = this.annotation.item.typeValue;
        if (type === 'hint' && (typeValue === 'ocr' || typeValue === 'formula' || typeValue === 'image')) {
            return ActionsHelpModeKeys[`${type}-${typeValue}`];
        }
        return ActionsHelpModeKeys[type];
    }
}
