{% extends "layout.html" %}
{% load post_helpers %}
{% load admin_urls %}

{% block extraheader %}
<meta content="{{ post.imageurl }}" property="og:image">
<meta content="{{ post.title }}" property="og:title">
<meta content="article" property="og:type">
<meta content="" property="og:url">
{% endblock %}

{% block content %}
<div class="large-article-header" style="background-image:url('{{ post.imageurl }}')">
    <div class="large-article-header-content">
        <div class="center-container">
            <div class="article-date">
                {% if post.post_type != 'N' %}
                    <p>{{ post.event_start|date:"d. F Y" }}</p>
                {% else %}
                    <p>{{ post.public_date|date:"d. F Y" }}</p>
                {% endif %}
            </div>

            <div class="article-title">
                <h1>{{ post.title|tags_to_url  }}</h1>
            </div>

            <div class="article-details">
                <a>
                {{ post.subtitle|default_if_none:"&nbsp;"|tags_to_url }}
                </a>
                {% if author_image and author %}
                    <div class="article-author">
                    <a href="{% url 'member' author.id %}">
                        <img src="{{ author_image }}" alt="" />&nbsp;{{ author.firstname }}
                    </a>
                    </div>
                {% elif post.author %}
                    <div class="article-author">
                    <a href="">
                        <img src="" alt="" />{{ post.author }}
                    </a>
                    </div>
                {% else %}
                    <div class="article-author">
                    <a href="">
                        <img src="" alt="" />fet.at Redaktion
                    </a>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<div class="grid-container">
    <div class="grid-x grid-padding-x padding-top-1">
        <div class="cell medium-8">
            {% for tag in post.get_tagnames %}
                {{ tag|tags_to_url }}
            {% endfor %}
            <hr>

            {% if post.has_agenda %}
                <h2>Agenda<a class="headerlink" id="agenda" href="#agenda" title="Permalink to Agenda"> #</a></h2>
                {{ post.agenda_html|safe }}
                <hr>
            {% elif post.body %}
                {{ post.body|safe|add_internal_links|tags_to_url }}
                <hr>
            {% endif %}

            {% if request.user.is_authenticated and post.has_protocol %}
                <h2>Protokoll<a class="headerlink" id="protocol" href="#protocol" title="Permalink to Protokoll"> #</a></h2>
                {{ post.protocol_html|safe }}
                <hr>
            {% endif %}

        </div>
        <div class="cell medium-4">
            <a href="{% url 'posts:posts.show' next %}">Nächster Artikel <span class="nav fa fa-chevron-right fa-1x"></span></a><br>

            {% if request.user.is_authenticated %}
                <hr>

                {% if post.has_agenda %}
                <a href="{{ ep_agenda_link }}">Agenda</a>
                    {% if filename_agenda %}
                    <a href="{% url 'posts:show_pdf_agenda' post.slug %}">
                        <i class="far fa-file-pdf"></i>
                    </a>
                    {% endif %}
                <br>
                {% endif %}

                {% if post.has_protocol %}
                <a href="{{ ep_protocol_link }}">Protokoll</a>
                    {% if filename_protocol %}
                    <a href="{% url 'posts:show_pdf_protocol' post.slug %}">
                        <i class="far fa-file-pdf"></i>
                    </a>
                    {% endif %}
                <br>
                <hr>
                {% endif %}

                {% if post.post_type == 'N' %}
                    <a href="{% url 'admin:posts_news_change' post.id %}">News bearbeiten</a>
                {% elif post.post_type == 'E' %}
                    <a href="{% url 'admin:posts_event_change' post.id %}">Event bearbeiten</a>
                {% elif post.post_type == 'F' %}
                    <a href="{% url 'admin:posts_fetmeeting_change' post.id %}">FET Sitzung bearbeiten</a>
                {% endif %}
            
            {% endif %}

            {% if post.event_start %}
                <hr>
                Start: {{ post.event_start|date:"d. F Y" }} {{ post.event_start|time:"H:i" }}<br>
            {% endif %}
            {% if post.event_end %}
                Ende: {{ post.event_end|date:"d. F Y" }} {{ post.event_end|time:"H:i" }}<br>
            {% endif %}

            {% if post.event_place %}
                Ort: {{ post.event_place }}
            {% endif %}

            {% if post.event_start %}
                {% include 'posts/partials/_date_box.html' %}
            {% endif %}

            {% if files %}
                <hr>
                Dokumente:

                <ul>
                {% for file in files %}
                    <li><a href="{{file.file_field.url}}" target="_blank">{{file.title}}</a></li>
                {% endfor %}
                </ul>
            
            {% endif %}

            <hr>

        </div>

    </div>

    <div class="grid-x grid-margin-x">
        {% for post in related_posts %}
        <div class="medium-6 large-4 small-12 cell">
            {% include 'posts/partials/_posts_hero.html' %}
        </div>
        {% endfor %}
    </div>
</div>
{% endblock %}
