{% extends "base.html" %}
{% load static claims_extras %}

{% block title %}{{ claim.title }} – Faktenkompass{% endblock %}
{% block meta_description %}{{ claim.short_answer|truncatewords:30 }}{% endblock %}

{% block content %}
<nav aria-label="Brotkrumen">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="{% url 'claims:home' %}">Themen</a></li>
        <li class="breadcrumb-item"><a href="{{ claim.category.get_absolute_url }}">{{ claim.category.name }}</a></li>
        <li class="breadcrumb-item active text-truncate" style="max-width: 10rem;">Behauptung</li>
    </ol>
</nav>

<article>
    <h1 class="fk-claim-title">{{ claim.title|quoted }}</h1>

    <div class="fk-meta-stack mb-3">
        {% status_badge claim %}
        {% evidence_badge claim %}
    </div>

    <div class="fk-card fk-answer-card">
        <p class="fk-section-label mb-2">Kurzantwort</p>
        <p>{{ claim.short_answer }}</p>
    </div>

    {% if claim.evidence_files.all %}
    <section class="fk-section">
        <p class="fk-section-label">Nachweise</p>
        <div class="d-flex flex-column gap-2">
            {% for evidence in claim.evidence_files.all %}
            {% if evidence.is_image %}
            <figure class="fk-card evidence-card mb-0">
                <button type="button" class="fk-img-open" data-src="{{ evidence.file.url }}"
                        data-caption="{{ evidence.caption|default:evidence.image_alt }}"
                        aria-label="Grafik im Vollbild anzeigen">
                    <img src="{{ evidence.file.url }}" alt="{{ evidence.image_alt }}"
                         class="evidence-img w-100" loading="lazy">
                </button>
                {% if evidence.caption %}
                <figcaption class="card-body py-2 px-3 small text-muted">{{ evidence.caption }}</figcaption>
                {% endif %}
            </figure>
            {% elif evidence.is_pdf %}
            <a href="{{ evidence.file.url }}" target="_blank" rel="noopener noreferrer" class="text-decoration-none">
                <div class="fk-card evidence-card">
                    <div class="card-body py-2 px-3 d-flex align-items-center gap-3">
                        <i class="bi bi-file-earmark-pdf fs-3 flex-shrink-0" style="color:#ef4444"></i>
                        <div class="min-w-0">
                            <span class="small fw-medium d-block" style="color:var(--fk-text)">{{ evidence.display_title }}</span>
                            {% if evidence.caption %}<span class="small text-muted">{{ evidence.caption }}</span>{% endif %}
                            <span class="small text-primary">PDF öffnen</span>
                        </div>
                    </div>
                </div>
            </a>
            {% endif %}
            {% endfor %}
        </div>
    </section>
    {% endif %}

    {% if claim.detailed_explanation %}
    <section class="fk-section">
        <p class="fk-section-label">Erklärung</p>
        <div class="fk-card fk-section-body">
            {{ claim.detailed_explanation|linebreaks }}
        </div>
    </section>
    {% endif %}

    {% if claim.sources.all %}
    <section class="fk-section">
        <p class="fk-section-label">Quellen</p>
        <div class="d-flex flex-column gap-2">
            {% for source in claim.sources.all %}
            <div class="fk-card fk-section-body">
                <a href="{{ source.url }}" target="_blank" rel="noopener noreferrer" class="fk-source-link">
                    {{ source.title }} <i class="bi bi-box-arrow-up-right"></i>
                </a>
                <p class="text-muted small mb-0">{{ source.organization }}</p>
                {% if source.description %}
                <p class="small mb-0 mt-1">{{ source.description }}</p>
                {% endif %}
            </div>
            {% endfor %}
        </div>
    </section>
    {% endif %}

    {% if claim.counter_arguments.all %}
    <section class="fk-section">
        <p class="fk-section-label">Gegenargumente</p>
        <div class="accordion fk-accordion" id="counterArgs">
            {% for ca in claim.counter_arguments.all %}
            <div class="accordion-item">
                <h2 class="accordion-header">
                    <button class="accordion-button collapsed py-2 small" type="button"
                            data-bs-toggle="collapse" data-bs-target="#collapse{{ forloop.counter }}">
                        {{ ca.argument }}
                    </button>
                </h2>
                <div id="collapse{{ forloop.counter }}" class="accordion-collapse collapse"
                     data-bs-parent="#counterArgs">
                    <div class="accordion-body py-2">
                        {{ ca.response|linebreaks }}
                    </div>
                </div>
            </div>
            {% endfor %}
        </div>
    </section>
    {% endif %}

    {% if claim.tags.all %}
    <div class="d-flex flex-wrap gap-1">
        {% for tag in claim.tags.all %}
        <span class="fk-tag">#{{ tag.name }}</span>
        {% endfor %}
    </div>
    {% endif %}
</article>

{% if related_claims %}
<aside class="mt-4 pt-4" style="border-top:1px solid var(--fk-border)">
    <p class="fk-section-label">Mehr zu {{ claim.category.name }}</p>
    <div class="d-flex flex-column gap-2">
        {% for related in related_claims %}
        <a href="{{ related.get_absolute_url }}" class="text-decoration-none">
            <div class="claim-card">
                <div class="card-body py-2">
                    <div class="mb-1">{% status_badge related %}</div>
                    <span class="claim-title small d-block">{{ related.title|quoted }}</span>
                </div>
            </div>
        </a>
        {% endfor %}
    </div>
</aside>
{% endif %}

<div id="fk-lightbox" class="fk-lightbox" hidden role="dialog" aria-modal="true" aria-label="Grafik Vollbild">
    <button type="button" class="fk-lightbox-backdrop" aria-label="Schließen"></button>
    <button type="button" class="fk-lightbox-close" aria-label="Schließen">
        <i class="bi bi-x-lg"></i>
    </button>
    <img class="fk-lightbox-img" src="" alt="">
    <p class="fk-lightbox-caption"></p>
</div>
{% endblock %}

{% block extra_js %}
<script src="{% static 'js/image-lightbox.js' %}" defer></script>
{% endblock %}
