{% extends "froide_govplan/base.html" %}
{% load i18n %}
{# TODO: i18n for all strings #}
{% load markup %}
{% load cms_tags %}
{% load follow_tags %}
{% load govplan %}
{% load form_helper %}
{% load content_helper %}
{% load thumbnail %}
{% block title %}
    {{ object.title }} - VerwaltungsTracker
{% endblock title %}
{% block metaDescription %}
    {{ object.quote | addquotes }}
{% endblock %}
{% block ogTitle %}
    {{ object.title }} - VerwaltungsTracker
{% endblock ogTitle %}
{% block ogDescription %}
    {{ object.quote | addquotes }}
{% endblock %}
{% block meta %}
    {% include "snippets/meta.html" %}
{% endblock meta %}
{% block app_body %}

    <h1 class="text-body-emphasis">{{ object.title }}</h1>
    <p class="fs-5 col-md-8">
        <div class="d-md-flex my-4 align-items-center">
            <ul class="list-unstyled d-flex m-0">
                <li>
                    <span class="badge text-bg-{{ object.get_status_css }} me-2">{{ object.get_status_display }}</span>
                </li>
                {% for cat in object.categories.all %}
                    <li>
                        <a href="{{ section.get_absolute_url }}"
                           class="badge text-bg-light text-decoration-none me-2">{{ cat.name }}</a>
                    </li>
                {% endfor %}
            </ul>
        </div>

        <div>
            <div class="row">
              <!-- Linke Spalte: Desktop: ca. 33% -->
              <div class="col-12 col-md-4 order-md-1 order-2">

                <dl>
                    {% if object.rating %}
                        <dt>Bewertung</dt>
                        <dd>
                            {{ object.get_rating_display }}
                        </dd>
                    {% endif %}
                    {% if object.measure %}
                        <dt>Art der Umsetzung</dt>
                        <dd>
                            {{ object.measure }}
                        </dd>
                    {% endif %}
                    {% if object.due_date %}
                        <dt>Frist</dt>
                        <dd>
                            {{ object.due_date|date:"SHORT_DATE_FORMAT" }}
                        </dd>
                    {% endif %}
                    {% if object.responsible_publicbody %}
                        <dt>Federführung</dt>
                        <dd>
                            <a href="#" class="text-decoration-none">{{ object.responsible_publicbody.name }}</a>
                        </dd>
                    {% endif %}
                    <br>
                    {% if object.responsible_publicbody %}
                        {% if not object.has_recent_foirequest and government.active %}
                            <p>
                                <a href="https://fragdenstaat.de/anfrage-stellen/an/{{ object.responsible_publicbody.other_names }}/?subject=Stand des Verwaltungsvorhabens „{{ object.title }}“&body=Dokumente, die den Stand des Verwaltungsvorhabens zum Thema {{ object.title }}, dokumentieren.&ref=verwaltungstracker:plan@358&tags=Verwaltungstracker&hide_public=1&hide_similar=1&hide_draft=1"
                                   target="_blank"
                                   class="btn btn-outline-primary btn-sm">Anfrage zum Vorhaben stellen</a>
                            </p>
                        {% elif object.has_recent_foirequest %}
                            {% with foirequest=object.get_recent_foirequest %}
                                <dt>Anfrage</dt>
                                <dd>
                                                                         <div class="mb-0 d-flex flex-column">
                                         <div class="flex-grow-1">
                                             <span class="mt-0 mb-1">
                                                 <a href="{{ foirequest.url }}" target="_blank" class="text-decoration-none">
                                                     {{ foirequest.title|default:"Aktuell laufende Anfrage" }}
                                                 </a>
                                                 <br>
                                                 <small class="text-gray-700">
                                                     gestartet am {{ foirequest.created_at|date:"d.m.Y" }},
                                                     vor {{ foirequest.created_at|timesince }}
                                                 </small>
                                             </span>
                                         </div>
                                     </div>
                                </dd>
                            {% endwith %}
                        {% endif %}
                    {% endif %}
                    {% if object.organization %}
                        <dt>Beobachtet von</dt>
                        <dd>
                            <a href="{{ object.organization.website }}">
                                {% if object.organization.logo %}
                                    {% if object.organization.logo.url.lower|slice:"-4:" == ".svg" %}
                                        {# djlint:off H006 #}
                                        <img src="{{ object.organization.logo.url }}"
                                             class="col-8 col-md-12 px-0"
                                             alt="{{ object.organization.name }}">
                                    {% else %}
                                        <img src="{% thumbnail object.organization.logo 300x0 %}"
                                             class="col-8 col-md-12 px-0"
                                             alt="{{ object.organization.name }}">
                                    {% endif %}
                                {% else %}
                                    {{ object.organization.name }}
                                {% endif %}
                            </a>
                        </dd>
                    {% endif %}
                </dl>

            </div>
              <!-- Rechte Spalte: Desktop: ca. 67% -->
              <div class="col-12 col-md-8 order-md-2 order-1">

                <dl>
                    {% if object.quote %}
                        <dt>Ausschnitt aus dem Verwaltungsvorhaben</dt>
                        <dd>
                            <blockquote>
                                {{ object.quote | addquotes | markdown }}
                            </blockquote>
                            {% with refs=object.get_reference_links %}
                                {% if refs %}
                                    <p>
                                        <span class="small">
                                            {% if refs|length > 1 %}
                                                Quellen:
                                            {% else %}
                                                Quelle:
                                            {% endif %}
                                        </span>
                                        {% for ref in refs %}
                                            <a href="{{ ref }}" class="badge text-bg-light me-2" target="_blank">{{ forloop.counter }}</a>
                                        {% endfor %}
                                    </p>
                                {% endif %}
                            {% endwith %}
                        {% endif %}
                    </dd>
                    {% if object.description %}
                        <div class="mt-3 mt-md-5">
                            <dt>Unsere Einschätzung</dt>
                            <dd>
                                {{ object.description | safe }}
                            </dd>
                        </div>
                    {% endif %}
                </dl>

                </div>
            </div>
        </div>

    </p>

        {% include "froide_govplan/plugins/updates.html" with wrapper_classes="col col-12 col-lg-6 d-flex mb-4" %}
        {% if government.active %}
        <div class="col">
            <div class="h-100 p-5 border rounded-3">
                <h2 style="font-size: 1.5rem;">Neue Entwicklung melden</h2>
                <p>
                    Gibt es Neuigkeiten zu diesem Vorhaben, die wir noch nicht erfasst haben?
                </p>
                <button type="button"
                    class="btn btn-outline-secondary"
                    data-bs-toggle="modal"
                    data-bs-target="#govplanupdate-proposal">Entwicklung melden</button>
                <div class="modal"
                        data-teleport="body"
                        tabindex="-1"
                        role="dialog"
                        id="govplanupdate-proposal">
                    <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h5 class="modal-title">Neue Entwicklung melden</h5>
                                <button type="button"
                                        class="btn-close"
                                        data-bs-dismiss="modal"
                                        aria-label="{% translate "Close" %}"></button>
                            </div>
                            <div class="modal-body">
                                <form method="post"
                                    action="{% url 'govplan:propose_planupdate' gov=object.government.slug plan=object.slug %}">
                                    {% csrf_token %}
                                    {% render_form update_proposal_form %}
                                    <button type="submit" class="btn btn-primary">Neue Entwicklung melden</button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {% endif %}
    </div>
 
{% endblock app_body %}
