import { ChangeDetectionStrategy, Component, inject, Input } from '@angular/core';
import { DOSSIER_TEMPLATE_ID, Justification } from '@red/domain';
import { CircleButtonTypes } from '@iqser/common-ui';
import { JustificationsDialogService } from '../justifications-dialog.service';
import { PermissionsService } from '@services/permissions.service';
import { getParam } from '@iqser/common-ui/lib/utils';

@Component({
    selector: 'redaction-table-item',
    templateUrl: './table-item.component.html',
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TableItemComponent {
    readonly #dossierTemplateId: string = getParam(DOSSIER_TEMPLATE_ID);
    readonly circleButtonTypes = CircleButtonTypes;
    @Input() justification: Justification;
    readonly canAddEditJustifications = inject(PermissionsService).canAddEditJustifications();

    constructor(private readonly _dialogService: JustificationsDialogService) {}

    openEditJustificationDialog() {
        this._dialogService.openDialog('addEditJustification', {
            justification: this.justification,
            dossierTemplateId: this.#dossierTemplateId,
        });
    }

    openConfirmDeleteDialog() {
        this._dialogService.confirmDelete([this.justification], this.#dossierTemplateId);
    }
}
