{% load static %}

<dialog
  id="publish_package_modal"
  class="modal"
  x-data="modalForm()"
  @close="reset()"
>
  <div class="modal-box">
    <!-- Header -->
    <h3 class="font-bold text-lg">Publish Package</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">
      <div class="alert alert-info">
        <svg
          xmlns="http://www.w3.org/2000/svg"
          fill="none"
          viewBox="0 0 24 24"
          class="h-6 w-6 shrink-0 stroke-current"
        >
          <path
            stroke-linecap="round"
            stroke-linejoin="round"
            stroke-width="2"
            d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
          ></path>
        </svg>
        <span
          >Clicking on Publish will make this Package publicly available!</span
        >
      </div>

      <form
        id="publish-package-modal-form"
        accept-charset="UTF-8"
        action="{{ current_package.url }}"
        method="post"
      >
        {% csrf_token %}
        <input type="hidden" name="hidden" value="publish-package" />
      </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('publish-package-modal-form')"
        :disabled="isSubmitting"
      >
        <span x-show="!isSubmitting">Publish</span>
        <span
          x-show="isSubmitting"
          class="loading loading-spinner loading-sm"
        ></span>
        <span x-show="isSubmitting">Publishing...</span>
      </button>
    </div>
  </div>

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