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

{% block title %}Hilfs-Infoboxen verwalten - Stiftungsverwaltung{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h1 class="h3">
                <i class="fas fa-info-circle text-primary me-2"></i>
                Hilfs-Infoboxen verwalten
            </h1>
            <div>
                <a href="{% url 'admin:stiftung_helpbox_add' %}" class="btn btn-primary">
                    <i class="fas fa-plus me-2"></i>Neue Hilfsbox erstellen
                </a>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-8">
                <div class="card shadow">
                    <div class="card-header bg-info text-white">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-list me-2"></i>Alle Hilfsboxen
                        </h5>
                    </div>
                    <div class="card-body p-0">
                        {% if help_boxes %}
                            <div class="table-responsive">
                                <table class="table table-hover mb-0">
                                    <thead class="table-light">
                                        <tr>
                                            <th>Seite</th>
                                            <th>Titel</th>
                                            <th>Status</th>
                                            <th>Zuletzt geändert</th>
                                            <th>Geändert von</th>
                                            <th>Aktionen</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for help_box in help_boxes %}
                                        <tr>
                                            <td>
                                                <span class="badge bg-secondary">{{ help_box.get_page_key_display }}</span>
                                            </td>
                                            <td>
                                                <strong>{{ help_box.title }}</strong>
                                                <br>
                                                <small class="text-muted">{{ help_box.content|truncatechars:80 }}</small>
                                            </td>
                                            <td>
                                                {% if help_box.is_active %}
                                                    <span class="badge bg-success">Aktiv</span>
                                                {% else %}
                                                    <span class="badge bg-danger">Inaktiv</span>
                                                {% endif %}
                                            </td>
                                            <td>
                                                {{ help_box.updated_at|date:"d.m.Y H:i" }}
                                            </td>
                                            <td>
                                                {{ help_box.updated_by|default:"-" }}
                                            </td>
                                            <td>
                                                <a href="{% url 'admin:stiftung_helpbox_change' help_box.id %}" 
                                                   class="btn btn-sm btn-outline-primary me-1" 
                                                   title="Bearbeiten">
                                                    <i class="fas fa-edit"></i>
                                                </a>
                                                <a href="{% url 'admin:stiftung_helpbox_delete' help_box.id %}" 
                                                   class="btn btn-sm btn-outline-danger" 
                                                   title="Löschen">
                                                    <i class="fas fa-trash"></i>
                                                </a>
                                            </td>
                                        </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        {% else %}
                            <div class="text-center py-4">
                                <i class="fas fa-info-circle fa-3x text-muted mb-3"></i>
                                <h5 class="text-muted">Keine Hilfsboxen gefunden</h5>
                                <p class="text-muted">Erstellen Sie Ihre erste Hilfsbox!</p>
                                <a href="{% url 'admin:stiftung_helpbox_add' %}" class="btn btn-primary">
                                    <i class="fas fa-plus me-2"></i>Hilfsbox erstellen
                                </a>
                            </div>
                        {% endif %}
                    </div>
                </div>
            </div>

            <div class="col-lg-4">
                <div class="card shadow">
                    <div class="card-header bg-light">
                        <h6 class="card-title mb-0">
                            <i class="fas fa-chart-pie me-2"></i>Statistiken
                        </h6>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <div class="d-flex justify-content-between">
                                <span>Gesamt:</span>
                                <strong>{{ help_boxes|length }}</strong>
                            </div>
                        </div>
                        <div class="mb-3">
                            <div class="d-flex justify-content-between">
                                <span>Aktiv:</span>
                                <strong class="text-success">{{ active_count }}</strong>
                            </div>
                        </div>
                        <div class="mb-3">
                            <div class="d-flex justify-content-between">
                                <span>Inaktiv:</span>
                                <strong class="text-danger">{{ inactive_count }}</strong>
                            </div>
                        </div>
                        <hr>
                        <h6 class="text-primary">Verfügbare Seiten:</h6>
                        <div class="small">
                            {% for key, display in available_pages %}
                                {% if key not in existing_pages %}
                                    <div class="mb-1">
                                        <span class="badge bg-light text-dark">{{ display }}</span>
                                        <a href="{% url 'admin:stiftung_helpbox_add' %}?page_key={{ key }}" 
                                           class="btn btn-sm btn-outline-primary ms-2">
                                            <i class="fas fa-plus"></i>
                                        </a>
                                    </div>
                                {% endif %}
                            {% endfor %}
                        </div>
                    </div>
                </div>

                <div class="card shadow mt-3">
                    <div class="card-header bg-light">
                        <h6 class="card-title mb-0">
                            <i class="fas fa-info me-2"></i>Hilfetipps
                        </h6>
                    </div>
                    <div class="card-body">
                        <div class="small">
                            <h6>Markdown Syntax:</h6>
                            <ul class="list-unstyled">
                                <li><code>**fett**</code> → <strong>fett</strong></li>
                                <li><code>*kursiv*</code> → <em>kursiv</em></li>
                                <li><code>`code`</code> → <code>code</code></li>
                                <li><code>[Link](url)</code> → <a href="#">Link</a></li>
                                <li><code>- Liste</code> → Aufzählung</li>
                                <li><code>1. Nummer</code> → Nummeriert</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
