{% load static %}

<dialog
  id="download_pathway_csv_modal"
  class="modal"
  x-data="modalForm()"
  @close="reset()"
>
  <div class="modal-box">
    <!-- Header -->
    <h3 class="font-bold text-lg">Download Pathway as CSV</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>
        By clicking on Download the Pathway will be converted into a CSV and
        directly downloaded.
      </p>

      <form
        id="download-pathway-csv-modal-form"
        accept-charset="UTF-8"
        action="{{ pathway.url }}"
        method="GET"
      >
        <input type="hidden" name="download" value="true" />
      </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('download-pathway-csv-modal-form'); $el.closest('dialog').close();"
        :disabled="isSubmitting"
      >
        <span x-show="!isSubmitting">Download</span>
        <span
          x-show="isSubmitting"
          class="loading loading-spinner loading-sm"
        ></span>
      </button>
    </div>
  </div>

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