{% extends "base.html" %}

{% load django_bootstrap5 %}
{% load bootstrap_helpers %}
{% load community_utils %}

{% block title %}
  {% if institution.name %}
    Edit {{ institution.abbreviation }}
  {% else %}
    Create a new institution
  {% endif %}
{% endblock %}

{% block headline %}
  {% if institution.name %}
    Edit {{ institution }}
  {% else %}
    Create a new institution
  {% endif %}
{% endblock %}

{% block breadcrumbs %}
  {% url 'institutions:institutions' as institutions_url %}
  {% with institutions_url=institutions_url|add:'?end_date__isnull=True' %}
    {% if institution.id %}
      {% breadcrumbs "Institutions"|combine:institutions_url institution.abbreviation|combine:institution.get_absolute_url "Edit"|combine:request.path %}
    {% else %}
      {% breadcrumbs "Institutions"|combine:institutions_url "New institution"|combine:request.path %}
    {% endif %}
  {% endwith %}
{% endblock %}

{% block footer %}
{{ block.super }}

<script>
  $(document).ready(function () {
    $("#city-form-content").html(`
      {% bootstrap_form form.city_form %}
      `
    );
  })
</script>

{% endblock %}

{% block content %}


<form role="form" method="post" enctype="multipart/form-data">
  {% csrf_token %}
  {% include "institutions/institution_form_content.html" %}

  <div class="row row-cols-auto m-3">
    {% bootstrap_button "OK" button_type="submit" extra_classes="me-2" %}
    {% bootstrap_button "Reset" button_type="reset"  %}
    {% if form.instance.pk %}
      {% bootstrap_button content="Cancel" extra_classes="ms-auto" button_type="link" href=institution.get_absolute_url %}
    {% else %}
      {% url "institutions:institutions" as institution_list %}
      {% bootstrap_button content="Cancel" extra_classes="ms-auto" button_type="link" href=institution_list %}
    {% endif %}
  </div>
</form>

{% endblock %}
