<dialog
  id="retrain_model_modal"
  class="modal"
  x-data="modalForm()"
  @close="reset()"
>
  <div class="modal-box max-w-3xl">
    <!-- Header -->
    <h3 class="text-lg font-bold">Retrain Model</h3>

    <!-- Close button (X) -->
    <form method="dialog">
      <button
        class="btn btn-sm btn-circle btn-ghost absolute top-2 right-2"
        :disabled="isSubmitting"
      >
        ✕
      </button>
    </form>

    <!-- Body -->
    <div class="py-4">
      <form
        id="retrain_model_form"
        accept-charset="UTF-8"
        action="{{ meta.current_object.url }}"
        method="post"
      >
        {% csrf_token %}
        <div class="alert alert-info mb-4">
          <span>
            To reflect changes in the rule or data packages, you can use the
            "Retrain" button, to let the model reflect the changes without
            creating a new model. While the model is retraining, it will be
            unavailable for prediction.
          </span>
        </div>
        <input type="hidden" name="hidden" value="retrain" />
      </form>
    </div>

    <!-- Footer -->
    <div class="modal-action">
      <button
        type="button"
        class="btn"
        onclick="this.closest('dialog').close()"
        :disabled="isSubmitting"
      >
        Cancel
      </button>
      <button
        type="button"
        class="btn btn-primary"
        @click="submit('retrain_model_form')"
        :disabled="isSubmitting"
      >
        <span x-show="!isSubmitting">Retrain</span>
        <span
          x-show="isSubmitting"
          class="loading loading-spinner loading-sm"
        ></span>
        <span x-show="isSubmitting">Retraining...</span>
      </button>
    </div>
  </div>

  <!-- Backdrop -->
  <form method="dialog" class="modal-backdrop">
    <button :disabled="isSubmitting">close</button>
  </form>
</dialog>
