{% load static %}

<dialog
  id="new_group_modal"
  class="modal"
  x-data="modalForm()"
  @close="reset()"
>
  <div class="modal-box">
    <!-- Header -->
    <h3 class="font-bold text-lg">New Group</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">
        Create new Group. You can assign users to the group once it is created.
        Description can be changed after creation.
      </p>

      <form
        id="new-group-modal-form"
        accept-charset="UTF-8"
        action="{{ SERVER_BASE }}/group"
        method="post"
      >
        {% csrf_token %}

        <div class="form-control mb-3">
          <label class="label" for="group-name">
            <span class="label-text">Name</span>
          </label>
          <input
            id="group-name"
            class="input input-bordered w-full"
            name="group-name"
            placeholder="Name"
            required
          />
        </div>

        <div class="form-control mb-3">
          <label class="label" for="group-description">
            <span class="label-text">Description</span>
          </label>
          <input
            id="group-description"
            type="text"
            class="input input-bordered w-full"
            placeholder="Description..."
            name="group-description"
          />
        </div>
      </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('new-group-modal-form')"
        :disabled="isSubmitting"
      >
        <span x-show="!isSubmitting">Submit</span>
        <span
          x-show="isSubmitting"
          class="loading loading-spinner loading-sm"
        ></span>
        <span x-show="isSubmitting">Creating...</span>
      </button>
    </div>
  </div>

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