{% extends 'base.html' %}
{% load humanize %}

{% block title %}Stiftungskonten - 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>Stiftungskonten
                </h1>
                <div class="btn-group" role="group">
                    <a href="{% url 'stiftung:geschaeftsfuehrung' %}" class="btn btn-outline-secondary">
                        <i class="fas fa-arrow-left me-1"></i>Zurück zur Übersicht
                    </a>
                    <a href="{% url 'stiftung:konto_create' %}" class="btn btn-primary">
                        <i class="fas fa-plus me-1"></i>Neues Konto
                    </a>
                </div>
            </div>
        </div>
    </div>

    <!-- Konten Liste -->
    <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-list me-2"></i>Alle Konten ({{ konten.count }})
                    </h6>
                </div>
                <div class="card-body">
                    {% if konten %}
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th>Bank</th>
                                        <th>Kontoname</th>
                                        <th>IBAN</th>
                                        <th>Typ</th>
                                        <th>Zinssatz</th>
                                        <th>Saldo</th>
                                        <th>Saldo-Datum</th>
                                        <th>Status</th>
                                        <th>Aktionen</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for konto in konten %}
                                    <tr>
                                        <td>
                                            <strong>{{ konto.bank_name }}</strong>
                                            {% if konto.bic %}
                                                <br><small class="text-muted">BIC: {{ konto.bic }}</small>
                                            {% endif %}
                                        </td>
                                        <td>{{ konto.kontoname }}</td>
                                        <td>
                                            <code>{{ konto.iban }}</code>
                                        </td>
                                        <td>
                                            <span class="badge bg-secondary">{{ konto.get_konto_typ_display }}</span>
                                        </td>
                                        <td>
                                            {% if konto.zinssatz %}
                                                {{ konto.zinssatz }}%
                                            {% else %}
                                                -
                                            {% endif %}
                                        </td>
                                        <td class="text-end">
                                            <strong 
                                                class="{% if konto.saldo < 0 %}text-danger{% elif konto.saldo > 1000 %}text-success{% endif %}">
                                                €{{ konto.saldo|floatformat:2 }}
                                            </strong>
                                        </td>
                                        <td>
                                            {% if konto.saldo_datum %}
                                                {{ konto.saldo_datum|date:"d.m.Y" }}
                                            {% else %}
                                                <span class="text-muted">-</span>
                                            {% endif %}
                                        </td>
                                        <td>
                                            {% if konto.aktiv %}
                                                <span class="badge bg-success">Aktiv</span>
                                            {% else %}
                                                <span class="badge bg-secondary">Inaktiv</span>
                                            {% endif %}
                                        </td>
                                        <td>
                                            <div class="btn-group btn-group-sm" role="group">
                                                <a href="{% url 'stiftung:konto_edit' konto.pk %}" class="btn btn-outline-primary" title="Bearbeiten">
                                                    <i class="fas fa-edit"></i>
                                                </a>
                                                <a href="{% url 'stiftung:konto_detail' konto.pk %}" class="btn btn-outline-info" title="Details">
                                                    <i class="fas fa-eye"></i>
                                                </a>
                                                {% if not konto.aktiv %}
                                                <a href="#" class="btn btn-outline-danger" title="Löschen">
                                                    <i class="fas fa-trash"></i>
                                                </a>
                                                {% endif %}
                                            </div>
                                        </td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                        
                        <!-- Zusammenfassung -->
                        <div class="row mt-4">
                            <div class="col-md-4">
                                <div class="card border-primary">
                                    <div class="card-body text-center">
                                        <i class="fas fa-university fa-2x text-primary mb-2"></i>
                                        <h5>{{ konten.count }}</h5>
                                        <small class="text-muted">Gesamt Konten</small>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="card border-success">
                                    <div class="card-body text-center">
                                        <i class="fas fa-check-circle fa-2x text-success mb-2"></i>
                                        <h5>{{ konten|length }}</h5>
                                        <small class="text-muted">Aktive Konten</small>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="card border-info">
                                    <div class="card-body text-center">
                                        <i class="fas fa-euro-sign fa-2x text-info mb-2"></i>
                                        <h5>€{{ gesamtsaldo|floatformat:2 }}</h5>
                                        <small class="text-muted">Gesamtsaldo</small>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                    {% else %}
                        <div class="text-center py-5">
                            <i class="fas fa-university fa-3x text-muted mb-3"></i>
                            <p class="text-muted">Noch keine Konten angelegt.</p>
                            <a href="{% url 'stiftung:konto_create' %}" class="btn btn-primary">
                                <i class="fas fa-plus me-1"></i>Erstes Konto anlegen
                            </a>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

{% endblock %}
