{% extends "base.html" %}

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

{% block content %}
<div class="container-fluid">
    <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-calendar-plus me-2"></i>{{ title }}
        </h1>
    </div>

    <div class="row">
        <div class="col-lg-8">
            <div class="card shadow">
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}
                        
                        <div class="row">
                            <div class="col-md-6">
                                <div class="mb-3">
                                    <label for="titel" class="form-label">Titel *</label>
                                    <input type="text" class="form-control" id="titel" name="titel" required>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="mb-3">
                                    <label for="datum" class="form-label">Datum *</label>
                                    <input type="date" class="form-control" id="datum" name="datum" required>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="mb-3">
                                    <label for="zeit" class="form-label">Uhrzeit</label>
                                    <input type="time" class="form-control" id="zeit" name="zeit">
                                    <small class="text-muted">Leer lassen für ganztägig</small>
                                </div>
                            </div>
                        </div>

                        <div class="mb-3">
                            <label for="beschreibung" class="form-label">Beschreibung</label>
                            <textarea class="form-control" id="beschreibung" name="beschreibung" rows="3"></textarea>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="mb-3">
                                    <label for="kategorie" class="form-label">Kategorie</label>
                                    <select class="form-select" id="kategorie" name="kategorie">
                                        <option value="termin">Termin/Meeting</option>
                                        <option value="zahlung">Zahlungserinnerung</option>
                                        <option value="deadline">Frist/Deadline</option>
                                        <option value="geburtstag">Geburtstag</option>
                                        <option value="vertrag">Vertrag läuft aus</option>
                                        <option value="pruefung">Prüfung/Nachweis</option>
                                        <option value="sonstiges">Sonstiges</option>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="mb-3">
                                    <label for="prioritaet" class="form-label">Priorität</label>
                                    <select class="form-select" id="prioritaet" name="prioritaet">
                                        <option value="niedrig">Niedrig</option>
                                        <option value="normal" selected>Normal</option>
                                        <option value="hoch">Hoch</option>
                                        <option value="kritisch">Kritisch</option>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="d-flex justify-content-between">
                            <a href="{% url 'stiftung:kalender' %}" class="btn btn-secondary">
                                <i class="fas fa-arrow-left me-1"></i>Abbrechen
                            </a>
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-save me-1"></i>Speichern
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <div class="col-lg-4">
            <div class="card border-0 bg-light">
                <div class="card-body">
                    <h6 class="card-title">
                        <i class="fas fa-info-circle me-2"></i>Hilfe
                    </h6>
                    <p class="small text-muted">
                        Erstellen Sie hier neue Kalenderereignisse für wichtige Termine, 
                        Zahlungserinnerungen oder andere stiftungsbezogene Ereignisse.
                    </p>
                    <hr>
                    <h6 class="small">Kategorien:</h6>
                    <ul class="small text-muted">
                        <li><strong>Termin:</strong> Meetings, Besprechungen</li>
                        <li><strong>Zahlung:</strong> Fällige Unterstützungen</li>
                        <li><strong>Deadline:</strong> Fristen für Nachweise</li>
                        <li><strong>Vertrag:</strong> Auslaufende Pachtverträge</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
// Set today as default date
document.addEventListener('DOMContentLoaded', function() {
    const dateInput = document.getElementById('datum');
    if (dateInput && !dateInput.value) {
        const today = new Date();
        const yyyy = today.getFullYear();
        const mm = String(today.getMonth() + 1).padStart(2, '0');
        const dd = String(today.getDate()).padStart(2, '0');
        dateInput.value = `${yyyy}-${mm}-${dd}`;
    }
});
</script>
{% endblock %}