{% extends "base_detail.html" %}

{% load guardian_tags %}
{% load institutions %}
{% load community_buttons %}
{% load community_badges %}
{% load community_utils %}
{% load activities %}
{% load bootstrap_helpers %}
{% load django_bootstrap5 %}
{% load members %}
{% load cms_tags %}
{% load events_programme %}
{% load sekizai_tags %}

{% block title %}
  {% block headline %}
    {% if contribution.pk %}
      Edit {{ contribution }}
    {% else %}
      Submit Contribution to {{ event }}
    {% endif %}
  {% endblock %}
{% endblock %}

{% block extrahead %}
  {{ block.super }}
  {{ contributingauthor_formset.media.css }}


  <style>
    input, select {width: 100%}
  </style>

  {% addtoblock "js" %}
    {{ contributingauthor_formset.media.js }}
  {% endaddtoblock %}

{% endblock %}

{% block breadcrumbs %}
  {% url "events:event-list" as event_list_url %}
  {% url "events:programme:session-list" session.event.slug as programme_url %}
  {% url "events:programme:contribution-list" event.slug as contributions_url %}
  {% if contribution.pk %}
    {% url "events:programme:contribution-track-list" contribution.event.slug contribution.activity.abbreviation as activity_url %}
    {% breadcrumbs "Events"|combine:event_list_url contribution.event.name|combine:contribution.event.get_absolute_url "Submissions"|combine:contributions_url contribution.activity.abbreviation|combine:activity_url contribution.title|combine:contribution.get_absolute_url "Edit"|combine:request.path %}
  {% else %}
    {% breadcrumbs "Events"|combine:event_list_url event.name|combine:event.get_absolute_url "Submissions"|combine:contributions_url "Submit"|combine:request.path %}
  {% endif %}
{% endblock %}

{% block sidebar_below %}
  {% block sidebar_left %}
    {% include "events/components/event_sidebar.html" %}
  {% endblock %}
{% endblock %}

{% block content %}

  {% block form_content %}
    <form role="form" method="post">
      {% csrf_token %}

      {% bootstrap_form form %}

      {% card header="(Co-)Authors" %}
        {% contributingauthor_formset_cards contributingauthor_formset author_formset affiliation_formset %}
      {% endcard %}

      <div class="row row-cols-auto mt-4">
        {% bootstrap_button "Submit" button_type="submit" extra_classes="ms-2" %}
        {% bootstrap_button "Reset" button_type="reset"  %}
        {% bootstrap_button content="Cancel" extra_classes="ms-auto" button_type="link" href=next|default:event.get_absolute_url %}
      </div>
    </form>
  {% endblock %}
{% endblock %}
