{% load static %}

<dialog
  id="engineer_pathway_modal"
  class="modal"
  x-data="modalForm()"
  @close="reset()"
>
  <div class="modal-box max-w-2xl">
    <!-- Header -->
    <h3 class="font-bold text-lg">Engineer Pathway</h3>

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

    <!-- Body -->
    <div class="py-4">
      <p class="mb-4">
        Engineering Package is a process used to identify potential intermediate
        transformation products. To achieve this, a pathway is predicted using
        an existing setting. The threshold is temporarily set to zero to ensure
        that even intermediates with very low probability are not filtered out.
        <br /><br />
        If any intermediates are found, two pathways will be saved in a
        generated Package:
        <br />
        1. The engineered Pathway with the identified intermediates highlighted.
        <br />
        2. The fully predicted Pathway preserved for further analysis.
        <br /><br />
        Note: This is an asynchronous process and may take a few minutes to
        complete. You will be redirected to a page containing details about the
        task and its status.
      </p>
      <form
        id="engineer-pathway-modal-form"
        accept-charset="UTF-8"
        action="{% url 'jobs' %}"
        method="post"
      >
        {% csrf_token %}

        <div class="form-control mb-3">
          <label class="label" for="engineer-setting">
            <span class="label-text">
              Select the Setting you want to use for pathway engineering
            </span>
          </label>
          <select
            id="engineer-setting"
            name="engineer-setting"
            class="select select-bordered w-full"
            required
          >
            <option value="" disabled selected>Select Setting</option>
            {% for s in meta.available_settings %}
              <option value="{{ s.url }}">{{ s.name|safe }}</option>
            {% endfor %}
          </select>
          <input
            type="hidden"
            name="pathway-to-engineer"
            value="{{ pathway.url }}"
          />
          <input type="hidden" name="job-name" value="engineer-pathway" />
        </div>
      </form>
    </div>

    <!-- Footer -->
    <div class="modal-action">
      <button
        type="button"
        class="btn"
        onclick="this.closest('dialog').close()"
        :disabled="isSubmitting"
      >
        Close
      </button>
      <button
        type="button"
        class="btn btn-primary"
        @click="submit('engineer-pathway-modal-form')"
        :disabled="isSubmitting"
      >
        <span x-show="!isSubmitting">Engineer</span>
        <span
          x-show="isSubmitting"
          class="loading loading-spinner loading-sm"
        ></span>
        <span x-show="isSubmitting">Engineering...</span>
      </button>
    </div>
  </div>

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