import { Component, inject, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { TranslateService } from '@ngx-translate/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

import SharedModule from 'app/shared/shared.module';

export const CONFIRM_EVENT = 'CONFIRM_EVENT';

@Component({
  standalone: true,
  templateUrl: './resilient-activity-actions-button-dialog.component.html',
  imports: [SharedModule, FormsModule],
})
export class ResilientActivityActionsButtonDialogComponent implements OnInit {
  activityKey?: string;
  
  safeBody?: SafeHtml;
  safeTitle?: SafeHtml;
  
  protected activeModal = inject(NgbActiveModal);
  protected translate = inject(TranslateService);
  protected sanitizer = inject(DomSanitizer);
  
  ngOnInit(): void {
    this.translate.get(`resilientApp.activities.${this.activityKey}.dialog.body`).subscribe((translation: string) => {
      this.safeBody = this.sanitizer.bypassSecurityTrustHtml(translation);
    });
    this.translate.get(`resilientApp.activities.${this.activityKey}.dialog.title`).subscribe((translation: string) => {
      this.safeTitle = this.sanitizer.bypassSecurityTrustHtml(translation);
    });
  }
  
  cancel(): void {
    this.activeModal.dismiss();
  }

  confirmActivityAction(): void {
    this.activeModal.close(CONFIRM_EVENT);
  }
}
