{% extends 'base.html' %}

{% block title %}{{ title }} - van Hees-Theyssen-Vogel'sche Stiftung{% endblock %}

{% block content %}

    <div class="row">
        <div class="col-12">
            <div class="d-sm-flex align-items-center justify-content-between mb-4">
                <h1 class="h3 mb-0 text-gray-800">
                    <i class="fas fa-university me-2"></i>{{ title }}
                </h1>
                <div class="btn-group" role="group">
                    <a href="{% url 'stiftung:konto_list' %}" class="btn btn-outline-secondary">
                        <i class="fas fa-arrow-left me-1"></i>Zurück zur Liste
                    </a>
                    {% if konto %}
                    <a href="{% url 'stiftung:konto_detail' konto.pk %}" class="btn btn-outline-info" title="Transaktionen anzeigen">
                        <i class="fas fa-list me-1"></i>Transaktionen
                    </a>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    <form method="post" novalidate>
        {% csrf_token %}
        
        <div class="row">
            <!-- Basisdaten -->
            <div class="col-xl-6 col-lg-6">
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary">
                            <i class="fas fa-info-circle me-2"></i>Kontodaten
                        </h6>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label for="{{ form.kontoname.id_for_label }}" class="form-label">Kontoname *</label>
                            {{ form.kontoname }}
                            {% if form.kontoname.errors %}
                                <div class="text-danger small">{{ form.kontoname.errors.0 }}</div>
                            {% endif %}
                        </div>
                        
                        <div class="mb-3">
                            <label for="{{ form.bank_name.id_for_label }}" class="form-label">Bank *</label>
                            {{ form.bank_name }}
                            {% if form.bank_name.errors %}
                                <div class="text-danger small">{{ form.bank_name.errors.0 }}</div>
                            {% endif %}
                        </div>
                        
                        <div class="mb-3">
                            <label for="{{ form.konto_typ.id_for_label }}" class="form-label">Kontotyp</label>
                            {{ form.konto_typ }}
                            {% if form.konto_typ.errors %}
                                <div class="text-danger small">{{ form.konto_typ.errors.0 }}</div>
                            {% endif %}
                        </div>

                        <div class="form-check mb-3">
                            {{ form.aktiv }}
                            <label class="form-check-label" for="{{ form.aktiv.id_for_label }}">
                                Aktiv
                            </label>
                            {% if form.aktiv.errors %}
                                <div class="text-danger small">{{ form.aktiv.errors.0 }}</div>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>

            <!-- Bankdaten -->
            <div class="col-xl-6 col-lg-6">
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary">
                            <i class="fas fa-credit-card me-2"></i>Bankdaten
                        </h6>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label for="{{ form.iban.id_for_label }}" class="form-label">IBAN</label>
                            {{ form.iban }}
                            {% if form.iban.errors %}
                                <div class="text-danger small">{{ form.iban.errors.0 }}</div>
                            {% endif %}
                            <div class="form-text">Internationale Bankkontonummer</div>
                        </div>
                        
                        <div class="mb-3">
                            <label for="{{ form.bic.id_for_label }}" class="form-label">BIC</label>
                            {{ form.bic }}
                            {% if form.bic.errors %}
                                <div class="text-danger small">{{ form.bic.errors.0 }}</div>
                            {% endif %}
                            <div class="form-text">Bank Identifier Code</div>
                        </div>
                    </div>
                </div>

                <!-- Saldo und Zinsen -->
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary">
                            <i class="fas fa-euro-sign me-2"></i>Saldo & Zinsen
                        </h6>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.saldo.id_for_label }}" class="form-label">Aktueller Saldo</label>
                                <div class="input-group">
                                    {{ form.saldo }}
                                    <span class="input-group-text">€</span>
                                </div>
                                {% if form.saldo.errors %}
                                    <div class="text-danger small">{{ form.saldo.errors.0 }}</div>
                                {% endif %}
                            </div>
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.saldo_datum.id_for_label }}" class="form-label">Saldo-Datum</label>
                                {{ form.saldo_datum }}
                                {% if form.saldo_datum.errors %}
                                    <div class="text-danger small">{{ form.saldo_datum.errors.0 }}</div>
                                {% endif %}
                            </div>
                        </div>
                        
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.zinssatz.id_for_label }}" class="form-label">Zinssatz</label>
                                <div class="input-group">
                                    {{ form.zinssatz }}
                                    <span class="input-group-text">%</span>
                                </div>
                                {% if form.zinssatz.errors %}
                                    <div class="text-danger small">{{ form.zinssatz.errors.0 }}</div>
                                {% endif %}
                            </div>
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.laufzeit_bis.id_for_label }}" class="form-label">Laufzeit bis</label>
                                {{ form.laufzeit_bis }}
                                {% if form.laufzeit_bis.errors %}
                                    <div class="text-danger small">{{ form.laufzeit_bis.errors.0 }}</div>
                                {% endif %}
                                <div class="form-text">Für Festgeld/Sparkonten</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Notizen -->
        <div class="row">
            <div class="col-12">
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary">
                            <i class="fas fa-sticky-note me-2"></i>Notizen
                        </h6>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label for="{{ form.notizen.id_for_label }}" class="form-label">Notizen</label>
                            {{ form.notizen }}
                            {% if form.notizen.errors %}
                                <div class="text-danger small">{{ form.notizen.errors.0 }}</div>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Form Errors -->
        {% if form.non_field_errors %}
        <div class="row">
            <div class="col-12">
                <div class="alert alert-danger">
                    <strong>Fehler:</strong>
                    {{ form.non_field_errors }}
                </div>
            </div>
        </div>
        {% endif %}

        <!-- Submit Buttons -->
        <div class="row">
            <div class="col-12">
                <div class="card shadow mb-4">
                    <div class="card-body text-end">
                        <a href="{% url 'stiftung:konto_list' %}" class="btn btn-secondary me-2">
                            <i class="fas fa-times me-1"></i>Abbrechen
                        </a>
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save me-1"></i>{{ submit_text }}
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </form>

{% endblock %}
