{% extends "base.html" %}

{% block title %}{{ title }}{% endblock %}

{% block content %}
<div class="container-fluid">
    <!-- Calendar Header with View Controls -->
    <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-list me-2"></i>{{ title }}
        </h1>
        <div class="d-flex gap-2">
            <!-- View Type Buttons -->
            <div class="btn-group" role="group">
                <a href="?view=month&year={{ year }}&month={{ month }}" 
                   class="btn btn-sm btn-outline-primary">
                    <i class="fas fa-calendar me-1"></i>Monat
                </a>
                <a href="?view=week" 
                   class="btn btn-sm btn-outline-primary">
                    <i class="fas fa-calendar-week me-1"></i>Woche
                </a>
                <a href="?view=agenda" 
                   class="btn btn-sm btn-outline-primary">
                    <i class="fas fa-list me-1"></i>Agenda
                </a>
                <a href="?view=list" 
                   class="btn btn-sm btn-primary">
                    <i class="fas fa-list-ul me-1"></i>Liste
                </a>
            </div>
            
            <a href="{% url 'stiftung:kalender_create' %}" class="btn btn-success">
                <i class="fas fa-plus me-1"></i>Neuer Termin
            </a>
        </div>
    </div>

    <!-- Event List -->
    <div class="row">
        <div class="col-12">
            <div class="card shadow">
                <div class="card-body">
                    {% if events %}
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th width="100">Datum</th>
                                    <th width="60">Zeit</th>
                                    <th>Titel</th>
                                    <th>Beschreibung</th>
                                    <th width="120">Kategorie</th>
                                    <th width="100">Priorität</th>
                                    <th width="80">Status</th>
                                    <th width="100">Aktionen</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for event in events %}
                                <tr class="{% if event.overdue %}table-danger{% elif event.completed %}table-success{% endif %}">
                                    <td>
                                        <strong>{{ event.date|date:"d.m.Y" }}</strong>
                                        <br>
                                        <small class="text-muted">{{ event.date|date:"l" }}</small>
                                    </td>
                                    <td>
                                        {% if event.time %}
                                        {{ event.time }}
                                        {% else %}
                                        <small class="text-muted">ganztags</small>
                                        {% endif %}
                                    </td>
                                    <td>
                                        <div class="d-flex align-items-center">
                                            <i class="{{ event.icon }} me-2 text-{{ event.color }}"></i>
                                            <strong>{{ event.title }}</strong>
                                        </div>
                                    </td>
                                    <td>
                                        <small>{{ event.description|default:"-" }}</small>
                                    </td>
                                    <td>
                                        <span class="badge bg-{{ event.color }}">
                                            {{ event.category|title }}
                                        </span>
                                    </td>
                                    <td>
                                        {% if event.priority == 'kritisch' %}
                                        <span class="badge bg-danger">{{ event.priority|title }}</span>
                                        {% elif event.priority == 'hoch' %}
                                        <span class="badge bg-warning">{{ event.priority|title }}</span>
                                        {% elif event.priority == 'normal' %}
                                        <span class="badge bg-primary">{{ event.priority|title }}</span>
                                        {% else %}
                                        <span class="badge bg-secondary">{{ event.priority|title }}</span>
                                        {% endif %}
                                    </td>
                                    <td>
                                        {% if event.overdue %}
                                        <span class="badge bg-danger">Überfällig</span>
                                        {% elif event.completed %}
                                        <span class="badge bg-success">Erledigt</span>
                                        {% else %}
                                        <span class="badge bg-info">Offen</span>
                                        {% endif %}
                                    </td>
                                    <td>
                                        <div class="btn-group btn-group-sm">
                                            {% if event.url %}
                                            <a href="{{ event.url }}" class="btn btn-outline-primary" title="Details">
                                                <i class="fas fa-eye"></i>
                                            </a>
                                            {% endif %}
                                            <a href="{% url 'stiftung:kalender_edit' event.id %}" class="btn btn-outline-secondary" title="Bearbeiten">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    {% else %}
                    <div class="text-center py-5">
                        <i class="fas fa-calendar-times fa-3x text-muted mb-3"></i>
                        <h5 class="text-muted">Keine Termine im gewählten Zeitraum</h5>
                        <p class="text-muted">Fügen Sie Ihren ersten Kalendereintrag hinzu.</p>
                        <a href="{% url 'stiftung:kalender_create' %}" class="btn btn-primary">
                            <i class="fas fa-plus me-1"></i>Termin hinzufügen
                        </a>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}