{% load crispy_forms_tags %}
{% include 'snippets/messages.html' with messages=messages %}

<h5 class="card-title">Update {{object}}</h5>

{% if form.errors %}
<div class="alert alert-danger">
  <strong>Invalid input:</strong>
  {{form.errors}}
</div>
{% endif %}

<form method="POST" enctype="multipart/form-data">
  {% csrf_token %}
  
  {% if form.helper %}{% crispy form %}{% else %}{{form|crispy}}{% endif %}

  <div class="gap-2 d-flex justify-content-center">
    <button type="submit" class="btn btn-primary">Save</button>
    <!-- Modal trigger button -->
    <button
      type="button"
      class="btn btn-danger"
      data-bs-toggle="modal"
      data-bs-target="#deleteModal"
    >
      Delete
    </button>
  </div>

</form>

<!-- Modal Body -->
<!-- if you want to close by clicking outside the modal, delete the last endpoint:data-bs-backdrop and data-bs-keyboard -->
<div
  class="modal fade"
  id="deleteModal"
  tabindex="-1"
  data-bs-backdrop="static"
  data-bs-keyboard="false"
  role="dialog"
  aria-labelledby="modalTitleId"
  aria-hidden="true"
>
  <div
    class="modal-dialog modal-dialog-scrollable modal-dialog-centered modal-sm"
    role="document"
  >
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalTitleId">Delete {{object}}</h5>
        <button
          type="button"
          class="btn-close"
          data-bs-dismiss="modal"
          aria-label="Close"
        ></button>
      </div>
      <form action="" method="post">
        {% csrf_token %}
        <div class="modal-body">
        <p>Are you sure you want to delete {{object}}?</p>
        <input name="delete" value="true" type="hidden" />
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
          Close
        </button>
        <button type="submit" class="btn btn-danger">Delete</button>
      </div>
      </form>
    </div>
  </div>
</div>
