import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["dialog"]

  confirm(event) {
    event.preventDefault()
    this.pendingForm = event.target
    this.dialogTarget.showModal()
  }

  ok() {
    this.dialogTarget.close()
    this.pendingForm?.submit()
  }

  cancel() {
    this.dialogTarget.close()
    this.pendingForm = null
  }

  backdropClick(event) {    
    console.info(event.target === this.dialogTarget)
    if (event.target === this.dialogTarget) this.cancel()
  }
}
