import { Component } from '@angular/core';
import { CircleButtonComponent, ConfirmOptions, IconButtonComponent, IqserDialogComponent } from '@iqser/common-ui';
import { MatDialogClose } from '@angular/material/dialog';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { IComponentLogEntry } from '@red/domain';
import { NgFor, NgIf } from '@angular/common';

interface RevertValueData {
    entry: IComponentLogEntry;
}
interface RevertValueResult {}

@Component({
    templateUrl: 'revert-value-dialog.component.html',
    styleUrls: ['./revert-value-dialog.component.scss'],
    standalone: true,
    imports: [CircleButtonComponent, IconButtonComponent, MatDialogClose, TranslateModule, NgFor, NgIf],
})
export class RevertValueDialogComponent extends IqserDialogComponent<RevertValueDialogComponent, RevertValueData, RevertValueResult> {
    protected readonly entry = this.data.entry;

    constructor(private readonly _translateService: TranslateService) {
        super();
    }
    save() {
        this.close(ConfirmOptions.CONFIRM);
    }

    get valueDescription(): string {
        const componentRuleString = this._translateService.instant('revert-value-dialog.component-rule');
        const valueDescription = this.entry.componentValues[0]?.valueDescription || '';
        return `<strong>${componentRuleString}</strong> ${valueDescription}`;
    }
}
