// assets/controllers/loading_button_controller.js
import {Controller} from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["text", "loader"];
  static values = {form: String};

  startLoading(event) {
    event.preventDefault();
    this.textTarget.classList.add("hidden");
    this.loaderTarget.classList.remove("hidden");
    this.element.disabled = true;

    if (this.hasFormValue) {
      const form = document.getElementById(this.formValue);
      if (form) {
        form.submit();
      }
    }
  }
}
