{% extends "base.html" %}

{% block title %}{{ page_title }} | Roadshow Calendar{% endblock %}

{% block content %}
<section class="section-shell page-top-space">
  <div class="container">
    <div class="row justify-content-center">
      <div class="col-xl-8">
        <div class="card-surface form-card">
          <div class="section-heading mb-4">
            <span class="eyebrow-pill">{% if form_mode == 'edit' %}Edit event{% else %}Create event{% endif %}</span>
            <h1 class="section-title">{{ form_title }}</h1>
            <p class="section-copy">{{ form_intro }}</p>
          </div>
          <form method="post" novalidate>
            {% csrf_token %}
            <div class="row g-3">
              {% for field in form %}
              <div class="{% if field.name == 'summary' %}col-12{% elif field.name == 'is_published' %}col-12{% else %}col-md-6{% endif %}">
                {% if field.name == 'is_published' %}
                <div class="form-check card-check">
                  {{ field }}
                  <label class="form-check-label" for="{{ field.id_for_label }}">Publish this event publicly</label>
                  {% if field.help_text %}<div class="form-help">{{ field.help_text }}</div>{% endif %}
                </div>
                {% else %}
                <label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
                {{ field }}
                {% if field.help_text %}<div class="form-help">{{ field.help_text }}</div>{% endif %}
                {% endif %}
                {% for error in field.errors %}<div class="field-error">{{ error }}</div>{% endfor %}
              </div>
              {% endfor %}
            </div>
            {% if form.non_field_errors %}
            <div class="field-error mt-3">{{ form.non_field_errors }}</div>
            {% endif %}
            <div class="d-flex gap-2 flex-wrap mt-4">
              <button class="btn btn-primary-brand" type="submit">{{ submit_label }}</button>
              <a class="btn btn-ghost" href="{% if event %}{% url 'event_dashboard_detail' event.slug %}{% else %}{% url 'event_dashboard' %}{% endif %}">Cancel</a>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</section>
{% endblock %}
