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

@Component({
    selector: 'redaction-table-item',
    templateUrl: './table-item.component.html',
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TableItemComponent {
    readonly #dossierTemplateId = getParam(DOSSIER_TEMPLATE_ID);
    @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);
    }
}
