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

@Component({
    selector: 'redaction-annotation-wrapper',
    templateUrl: './annotation-wrapper.component.html',
    styleUrls: ['./annotation-wrapper.component.scss'],
})
export class AnnotationWrapperComponent implements OnChanges {
    readonly #isDocumine = getConfig().IS_DOCUMINE;
    protected readonly _pdfProxyService = inject(PdfProxyService);
    protected readonly _multiSelectService = inject(MultiSelectService);
    @Input({ required: true }) annotation!: ListItem<AnnotationWrapper>;
    @HostBinding('attr.annotation-id') annotationId: string;
    @HostBinding('class.active') active = false;
    actionsHelpModeKey?: string;

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

    #getActionsHelpModeKey(): string {
        if (!this.#isDocumine) {
            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];
        }
        return '';
    }
}
