{% extends 'base/layout.html' %}
{% load i18n %}

{% comment %}
Blocks:
  form: Content within the <form> element
  buttons: Form submission buttons

Context:
  object: Python instance of the object being edited
  form: The edit form
  return_url: The URL to which the user is redirected after submitting the form
{% endcomment %}

{% block title %}
  {% if object.pk %}
    {% trans "Editing" %} {{ object|meta:"verbose_name" }} {{ object }}
  {% else %}
    {% blocktrans trimmed with object_type=object|meta:"verbose_name" %}
      Add a new {{ object_type }}
    {% endblocktrans %}
  {% endif %}
{% endblock title %}

{% block tabs %}
  <ul class="nav nav-tabs px-3">
    <li class="nav-item" role="presentation">
      <button class="nav-link active" id="edit-form-tab" data-bs-toggle="tab" data-bs-target="#edit-form" type="button" role="tab" aria-controls="edit-form" aria-selected="true">
        {% if object.pk %}{% trans "Edit" %}{% else %}{% trans "Create" %}{% endif %}
      </button>
    </li>
  </ul>
{% endblock tabs %}

{% block content-wrapper %}
  <div class="tab-content">
    <div class="tab-pane show active" id="edit-form" role="tabpanel" aria-labelledby="object-list-tab">

      {# Warn about missing prerequisite objects #}
      {% if prerequisite_model %}
        {% include 'inc/missing_prerequisites.html' %}
      {% endif %}

      {# Link to model documentation #}
      {% if settings.DOCS_ROOT and object.docs_url %}
        <div class="float-end">
          <a href="{{ object.docs_url }}" target="_blank" class="btn btn-sm btn-outline-secondary" title="{% trans "View model documentation" %}">
            <i class="mdi mdi-help-circle"></i> {% trans "Help" %}
          </a>
        </div>
      {% endif %}

      <form action="" method="post" enctype="multipart/form-data" class="form-object-edit mt-5">
        {% csrf_token %}

        <div id="form_fields">
          {% block form %}
            {% include 'htmx/form.html' %}
          {% endblock form %}
        </div>

        <div class="text-end my-3">
          {% block buttons %}
            {% if object.pk %}
              <button type="submit" name="_update" class="btn btn-primary">
                {% trans "Save" %}
              </button>
            {% else %}
              <button type="submit" name="_create" class="btn btn-primary">
                {% trans "Create" %}
              </button>
              <button type="submit" name="_addanother" class="btn btn-outline-primary">
                {% trans "Create & Add Another" %}
              </button>
            {% endif %}
            <a class="btn btn-outline-danger" href="{{ return_url }}">{% trans "Cancel" %}</a>
          {% endblock buttons %}
        </div>
      </form>
    </div>
  </div>

{% endblock content-wrapper %}

{% block modals %}
  {% include 'inc/htmx_modal.html' with size='lg' %}
{% endblock %}
