{% extends "base.html" %}
{% block content %}
<h1 class="mb-4">Unvollständige Vorgaben</h1>

{% if vorgaben_data %}
    <div class="table-responsive">
        <table class="table table-striped table-hover">
            <thead class="table-dark">
                <tr>
                    <th>Vorgabe</th>
                    <th class="text-center">Referenzen</th>
                    <th class="text-center">Stichworte</th>
                    <th class="text-center">Text</th>
                    <th class="text-center">Checklistenfragen</th>
                </tr>
            </thead>
            <tbody>
                {% for item in vorgaben_data %}
                <tr>
                    <td>
                        <a href="/autorenumgebung/dokumente/vorgabe/{{ item.vorgabe.id }}/change/" 
                           class="text-decoration-none" target="_blank">
                            <strong>{{ item.vorgabe.Vorgabennummer }}</strong><br>
                            <small class="text-muted">{{ item.vorgabe.titel }}</small><br>
                            <small class="text-muted">{{ item.vorgabe.dokument.nummer }} – {{ item.vorgabe.dokument.name }}</small>
                        </a>
                    </td>
                    <td class="text-center align-middle">
                        {% if item.has_references %}
                            <span class="text-success fs-4">✓</span>
                        {% else %}
                            <span class="text-danger fs-4">✗</span>
                        {% endif %}
                    </td>
                    <td class="text-center align-middle">
                        {% if item.has_stichworte %}
                            <span class="text-success fs-4">✓</span>
                        {% else %}
                            <span class="text-danger fs-4">✗</span>
                        {% endif %}
                    </td>
                    <td class="text-center align-middle">
                        {% if item.has_text %}
                            <span class="text-success fs-4">✓</span>
                        {% else %}
                            <span class="text-danger fs-4">✗</span>
                        {% endif %}
                    </td>
                    <td class="text-center align-middle">
                        {% if item.has_checklistenfragen %}
                            <span class="text-success fs-4">✓</span>
                        {% else %}
                            <span class="text-danger fs-4">✗</span>
                        {% endif %}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    <!-- Summary -->
    <div class="row mt-4">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">Zusammenfassung</h5>
                </div>
                <div class="card-body">
                    <div class="row text-center">
                        <div class="col-md-3">
                            <div class="p-3">
                                <h4 class="text-danger" id="no-references-count">0</h4>
                                <p class="mb-0">Ohne Referenzen</p>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="p-3">
                                <h4 class="text-danger" id="no-stichworte-count">0</h4>
                                <p class="mb-0">Ohne Stichworte</p>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="p-3">
                                <h4 class="text-danger" id="no-text-count">0</h4>
                                <p class="mb-0">Ohne Text</p>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="p-3">
                                <h4 class="text-danger" id="no-checklistenfragen-count">0</h4>
                                <p class="mb-0">Ohne Checklistenfragen</p>
                            </div>
                        </div>
                    </div>
                    <div class="row mt-3">
                        <div class="col-12 text-center">
                            <h4 class="text-primary">Gesamt: {{ vorgaben_data|length }} unvollständige Vorgaben</h4>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% else %}
    <div class="alert alert-success" role="alert">
        <h4 class="alert-heading">
            <span class="emoji-icon">✅</span> Alle Vorgaben sind vollständig!
        </h4>
        <p>Alle Vorgaben haben Referenzen, Stichworte, Text und Checklistenfragen.</p>
        <hr>
        <p class="mb-0">
            <a href="{% url 'standard_list' %}" class="btn btn-primary">
                <span class="emoji-icon">📋</span> Zurück zur Übersicht
            </a>
        </p>
    </div>
{% endif %}

<div class="mt-3">
    <a href="{% url 'standard_list' %}" class="btn btn-secondary">
        <span class="emoji-icon">←</span> Zurück zur Übersicht
    </a>
</div>

<script>
// Update summary counts
document.addEventListener('DOMContentLoaded', function() {
    let noReferences = 0;
    let noStichworte = 0;
    let noText = 0;
    let noChecklistenfragen = 0;
    
    const rows = document.querySelectorAll('tbody tr');
    rows.forEach(function(row) {
        const cells = row.querySelectorAll('td');
        if (cells.length >= 5) {
            if (cells[1].textContent.trim() === '✗') noReferences++;
            if (cells[2].textContent.trim() === '✗') noStichworte++;
            if (cells[3].textContent.trim() === '✗') noText++;
            if (cells[4].textContent.trim() === '✗') noChecklistenfragen++;
        }
    });
    
    document.getElementById('no-references-count').textContent = noReferences;
    document.getElementById('no-stichworte-count').textContent = noStichworte;
    document.getElementById('no-text-count').textContent = noText;
    document.getElementById('no-checklistenfragen-count').textContent = noChecklistenfragen;
});
</script>
{% endblock %}