{% load static %}

<dialog
  id="edit_password_modal"
  class="modal"
  x-data="modalForm()"
  @close="reset()"
>
  <div class="modal-box">
    <!-- Header -->
    <h3 class="font-bold text-lg">Update your Password</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">
        To change your password please fill out the following inputs
      </p>

      <form
        id="edit-password-modal-form"
        accept-charset="UTF-8"
        action=""
        method="post"
      >
        {% csrf_token %}
        <input type="hidden" name="hidden" value="update-password" />

        <div class="form-control mb-3">
          <label class="label" for="old-password">
            <span class="label-text">Old Password</span>
          </label>
          <input
            id="old-password"
            class="input input-bordered w-full"
            name="old-password"
            type="password"
            autocomplete="current-password"
            required
          />
        </div>

        <div class="form-control mb-3">
          <label class="label" for="new-password">
            <span class="label-text">New Password</span>
          </label>
          <input
            id="new-password"
            class="input input-bordered w-full"
            name="new-password"
            type="password"
            autocomplete="new-password"
            required
          />
        </div>

        <div class="form-control mb-3">
          <label class="label" for="new-password-repeat">
            <span class="label-text">Repeat New Password</span>
          </label>
          <input
            id="new-password-repeat"
            class="input input-bordered w-full"
            name="new-password-repeat"
            type="password"
            autocomplete="new-password"
            required
            @input="validatePasswordMatch('new-password', 'new-password-repeat')"
          />
          <label class="label" x-show="errors['new-password-repeat']">
            <span
              class="label-text-alt text-error"
              x-text="errors['new-password-repeat']"
            ></span>
          </label>
        </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="if (validatePasswordMatch('new-password', 'new-password-repeat')) submit('edit-password-modal-form')"
        :disabled="isSubmitting"
      >
        <span x-show="!isSubmitting">Update</span>
        <span
          x-show="isSubmitting"
          class="loading loading-spinner loading-sm"
        ></span>
        <span x-show="isSubmitting">Updating...</span>
      </button>
    </div>
  </div>

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