{% extends 'base.html' %}

{% block title %}{{ title }} – Stiftungsverwaltung{% endblock %}

{% block content %}
<div class="container-fluid py-4">
    <div class="row">
        <div class="col-12">
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="{% url 'stiftung:veranstaltung_list' %}">Veranstaltungen</a></li>
                    <li class="breadcrumb-item"><a href="{% url 'stiftung:veranstaltung_detail' veranstaltung.pk %}">{{ veranstaltung.titel }}</a></li>
                    <li class="breadcrumb-item active">{{ title }}</li>
                </ol>
            </nav>
            <h1 class="h3 mb-4">
                <i class="fas fa-user-plus text-primary me-2"></i>{{ title }}
            </h1>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-8">
            <div class="card shadow-sm">
                <div class="card-header bg-dark text-white">
                    <i class="fas fa-user me-2"></i>Teilnehmerdaten
                </div>
                <div class="card-body">
                    <form method="post" novalidate>
                        {% csrf_token %}

                        {% if form.non_field_errors %}
                        <div class="alert alert-danger">
                            <ul class="mb-0">
                                {% for error in form.non_field_errors %}
                                <li>{{ error }}</li>
                                {% endfor %}
                            </ul>
                        </div>
                        {% endif %}

                        <div class="row">
                            <div class="col-md-4 mb-3">
                                <label for="{{ form.anrede.id_for_label }}" class="form-label">{{ form.anrede.label }}</label>
                                {{ form.anrede }}
                            </div>
                            <div class="col-md-4 mb-3">
                                <label for="{{ form.vorname.id_for_label }}" class="form-label">{{ form.vorname.label }} *</label>
                                {{ form.vorname }}
                                {% if form.vorname.errors %}<div class="invalid-feedback d-block">{{ form.vorname.errors.0 }}</div>{% endif %}
                            </div>
                            <div class="col-md-4 mb-3">
                                <label for="{{ form.nachname.id_for_label }}" class="form-label">{{ form.nachname.label }} *</label>
                                {{ form.nachname }}
                                {% if form.nachname.errors %}<div class="invalid-feedback d-block">{{ form.nachname.errors.0 }}</div>{% endif %}
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.strasse.id_for_label }}" class="form-label">{{ form.strasse.label }}</label>
                                {{ form.strasse }}
                            </div>
                            <div class="col-md-2 mb-3">
                                <label for="{{ form.plz.id_for_label }}" class="form-label">{{ form.plz.label }}</label>
                                {{ form.plz }}
                            </div>
                            <div class="col-md-4 mb-3">
                                <label for="{{ form.ort.id_for_label }}" class="form-label">{{ form.ort.label }}</label>
                                {{ form.ort }}
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.email.id_for_label }}" class="form-label">{{ form.email.label }}</label>
                                {{ form.email }}
                            </div>
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.rsvp_status.id_for_label }}" class="form-label">{{ form.rsvp_status.label }}</label>
                                {{ form.rsvp_status }}
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.paechter.id_for_label }}" class="form-label">{{ form.paechter.label }}</label>
                                {{ form.paechter }}
                                <div class="form-text">Optional: Verknüpfung mit bestehendem Pächter</div>
                            </div>
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.destinataer.id_for_label }}" class="form-label">{{ form.destinataer.label }}</label>
                                {{ form.destinataer }}
                                <div class="form-text">Optional: Verknüpfung mit bestehendem Destinatär</div>
                            </div>
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.bemerkungen.id_for_label }}" class="form-label">{{ form.bemerkungen.label }}</label>
                            {{ form.bemerkungen }}
                        </div>

                        <hr>
                        <div class="d-flex justify-content-between">
                            <a href="{% url 'stiftung:veranstaltung_detail' veranstaltung.pk %}" class="btn btn-secondary">
                                <i class="fas fa-times me-2"></i>Abbrechen
                            </a>
                            <button type="submit" class="btn btn-success">
                                <i class="fas fa-save me-2"></i>
                                {% if teilnehmer %}Aktualisieren{% else %}Hinzufügen{% endif %}
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
