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

{% block title %}{{ title }} - Stiftungsverwaltung{% endblock %}

{% block content %}

    <div class="row">
        <div class="col-12">
            <!-- Header -->
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h1 class="h3">
                    <i class="fas fa-file-alt text-primary me-2"></i>{{ title }}
                </h1>
                <div class="btn-group" role="group">
                    <a href="{% url 'stiftung:dokument_update' dokument.pk %}" class="btn btn-warning">
                        <i class="fas fa-edit me-2"></i>Bearbeiten
                    </a>
                    <a href="{% url 'stiftung:dokument_delete' dokument.pk %}" class="btn btn-danger">
                        <i class="fas fa-trash me-2"></i>Löschen
                    </a>
                </div>
            </div>

            <div class="row">
                <!-- Main Information -->
                <div class="col-lg-8">
                    <!-- Dokument Details -->
                    <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>Dokumentdetails
                            </h6>
                        </div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-6">
                                    <h6 class="text-primary">Titel</h6>
                                    <p class="mb-3">{{ dokument.titel }}</p>
                                    
                                    <h6 class="text-primary">Kontext</h6>
                                    <p class="mb-3">
                                        <span class="badge bg-secondary">{{ dokument.get_kontext_display }}</span>
                                    </p>
                                </div>
                                <div class="col-md-6">
                                    <h6 class="text-primary">Paperless ID</h6>
                                    <p class="mb-3">
                                        <code>{{ dokument.paperless_document_id }}</code>
                                    </p>
                                    
                                    <h6 class="text-primary">Erstellt</h6>
                                    <p class="mb-3">{{ dokument.id }}</p>
                                </div>
                            </div>
                            
                            {% if dokument.beschreibung %}
                            <hr class="my-3">
                            <h6 class="text-primary">Beschreibung</h6>
                            <p class="mb-0">{{ dokument.beschreibung }}</p>
                            {% endif %}
                        </div>
                    </div>

                    <!-- Verknüpfungen -->
                    <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-link me-2"></i>Verknüpfungen
                            </h6>
                        </div>
                        <div class="card-body">
                            {% if dokument.foerderung_set.exists or dokument.verpachtung_set.exists %}
                                {% if dokument.foerderung_set.exists %}
                                <h6 class="text-primary">Förderungen</h6>
                                <div class="list-group list-group-flush mb-3">
                                    {% for foerderung in dokument.foerderung_set.all %}
                                    <div class="list-group-item d-flex justify-content-between align-items-center">
                                        <div>
                                            <strong>{{ foerderung.person.get_full_name }}</strong> - {{ foerderung.jahr }}
                                            <br>
                                            <small class="text-muted">€{{ foerderung.betrag|floatformat:2 }}</small>
                                        </div>
                                        <a href="{% url 'stiftung:foerderung_detail' foerderung.pk %}" class="btn btn-sm btn-outline-primary">
                                            <i class="fas fa-eye"></i>
                                        </a>
                                    </div>
                                    {% endfor %}
                                </div>
                                {% endif %}
                                
                                {% if dokument.verpachtung_set.exists %}
                                <h6 class="text-primary">Verpachtungen</h6>
                                <div class="list-group list-group-flush">
                                    {% for verpachtung in dokument.verpachtung_set.all %}
                                    <div class="list-group-item d-flex justify-content-between align-items-center">
                                        <div>
                                            <strong>{{ verpachtung.vertragsnummer }}</strong> - {{ verpachtung.land.gemeinde }}
                                            <br>
                                            <small class="text-muted">{{ verpachtung.paechter.get_full_name }}</small>
                                        </div>
                                        <a href="{% url 'stiftung:verpachtung_detail' verpachtung.pk %}" class="btn btn-sm btn-outline-primary">
                                            <i class="fas fa-eye"></i>
                                        </a>
                                    </div>
                                    {% endfor %}
                                </div>
                                {% endif %}
                            {% else %}
                                <div class="text-center py-4">
                                    <i class="fas fa-link fa-3x text-muted mb-3"></i>
                                    <h5 class="text-muted">Keine Verknüpfungen</h5>
                                    <p class="text-muted">Dieses Dokument ist noch nicht mit Förderungen oder Verpachtungen verknüpft.</p>
                                </div>
                            {% endif %}
                        </div>
                    </div>
                </div>

                <!-- Sidebar -->
                <div class="col-lg-4">
                    <!-- Quick Stats -->
                    <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-chart-pie me-2"></i>Übersicht
                            </h6>
                        </div>
                        <div class="card-body">
                            <div class="row text-center">
                                <div class="col-6">
                                    <div class="border-end">
                                        <h4 class="text-primary">{{ dokument.foerderung_set.count }}</h4>
                                        <small class="text-muted">Förderungen</small>
                                    </div>
                                </div>
                                <div class="col-6">
                                    <h4 class="text-success">{{ dokument.verpachtung_set.count }}</h4>
                                    <small class="text-muted">Verpachtungen</small>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Actions -->
                    <div class="card shadow">
                        <div class="card-header py-3">
                            <h6 class="m-0 font-weight-bold text-primary">
                                <i class="fas fa-bolt me-2"></i>Schnellzugriff
                            </h6>
                        </div>
                        <div class="card-body">
                            <div class="d-grid gap-2">
                                <a href="{% url 'stiftung:dokument_update' dokument.pk %}" class="btn btn-warning">
                                    <i class="fas fa-edit me-2"></i>Dokument bearbeiten
                                </a>
                                <a href="{% url 'stiftung:dokument_list' %}" class="btn btn-outline-secondary">
                                    <i class="fas fa-arrow-left me-2"></i>Zurück zur Liste
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

{% endblock %} 
