import { Component, Inject } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { InternationalizationService } from '../../../../services/internationalization/internationalization.service';

@Component({
  selector: 'app-change-status-workflow',
  templateUrl: './change-status-workflow.component.html',
  styleUrl: './change-status-workflow.component.css',
  standalone: false,
})
export class ChangeStatusWorkflowComponent {
  public formGroup: FormGroup;
  public newStatus: string;

  constructor(
    public dialogRef: MatDialogRef<ChangeStatusWorkflowComponent>,
    @Inject(MAT_DIALOG_DATA) public data: { currentStatus: string },
    public interService: InternationalizationService
  ) {
    this.newStatus = data.currentStatus === 'Activo' ? 'Eliminado' : 'Activo';
    this.formGroup = new FormGroup({
      COMENTARIO_CAMBIO: new FormControl(null, Validators.required),
    });
  }

  public save(): void {
    if (this.formGroup.valid) {
      this.dialogRef.close({
        comentario: this.formGroup.get('COMENTARIO_CAMBIO')?.value,
        newStatus: this.newStatus
      });
    }
  }

  public close(): void {
    this.dialogRef.close();
  }
}