import { Component, EventEmitter, Input, Output } from '@angular/core'

@Component({
  selector: 'app-confirm-modal',
  templateUrl: './confirm-modal.component.html',
  standalone: false
})
export class ConfirmModalComponent {
  @Input() open = false
  @Input() title = 'Confirm'
  @Input() message = ''
  @Input() confirmText = 'Yes'
  @Input() cancelText = 'No'

  @Output() result = new EventEmitter<boolean>()

  onConfirm() {
    this.result.emit(true)
  }

  onCancel() {
    this.result.emit(false)
  }

  onClrModalOpenChange(value: boolean) {
    // Close triggered by X / outside / Esc — treat as cancel. Only emit
    // when modal was actually open (avoid double-emit when parent closes
    // us via [open]=false in response to the Yes/No button).
    if (!value && this.open) this.result.emit(false)
  }
}
