{% load static %}
{% load activity_tags %}
<div class="post {% if reply %}reply{% endif %} {{ post.summary_class }}" data-takahe-id="{{ post.id }}" role="article" tabindex="0">

    <div class="post-banner">
        {% include "identity/_identity_banner.html" with identity=post.author %}
        <div>
            <time _="on click go url {% if link_original %}{{ post.url }}{% else %}{{ post.urls.view }}{% endif %} then halt">
                {% if post.visibility == 0 %}
                    <i class="visibility fa-solid fa-earth-oceania" title="Public" aria-label="public"></i>
                {% elif post.visibility == 1 %}
                    <i class="visibility fa-solid fa-lock-open" title="Unlisted" aria-label="unlisted"></i>
                {% elif post.visibility == 2 %}
                    <i class="visibility fa-solid fa-lock" title="Followers Only" aria-label="followers only"></i>
                {% elif post.visibility == 3 %}
                    <i class="visibility fa-solid fa-at" title="Mentioned Only" aria-label="mentioned only"></i>
                {% elif post.visibility == 4 %}
                    <i class="visibility fa-solid fa-link-slash" title="Local Only" aria-label="local only"></i>
                {% endif %}
                {% if post.published %}
                    <a href="{% if link_original %}{{ post.url }}{% else %}{{ post.urls.view }}{% endif %}" title="{{ post.published }}">{{ post.published | timedeltashort }}</a>
                {% else %}
                    <a href="{% if link_original %}{{ post.url }}{% else %}{{ post.urls.view }}{% endif %}" title="{{ post.created }}">{{ post.created | timedeltashort }}</a>
                {% endif %}
            </time>
        </div>
    </div>

    {% if post.summary %}
        <div class="summary" _="on click or keyup[key is 'Enter'] toggle .enabled on <.{{ post.summary_class }} .summary/> then toggle .hidden on <.{{ post.summary_class }} .content/> then halt" tabindex="0">
            {{ post.summary }}
        </div>
    {% endif %}

    <div class="content {% if post.summary %}hidden {% endif %}">
        {{ post.safe_content_local }}

        {% if post.attachments.exists %}
            <div class="attachments">
                {% for attachment in post.attachments.all %}
                    {% if attachment.is_image %}
                        <a href="{{ attachment.full_url.relative }}" class="image" target="_blank"
                            _="on click halt the event then call imageviewer.show(me)">
                            <img src="{{ attachment.thumbnail_url.relative }}" title="{{ attachment.name }}" alt="{{ attachment.name|default:'(no description)' }}" loading="lazy" data-original-url="{{ attachment.full_url.relative }}">
                            {% if attachment.name %}
                                <div class="badge">ALT</div>
                            {% endif %}
                        </a>
                    {% elif attachment.is_video %}
                        <a href="{{ attachment.full_url.relative }}" class="video">
                            <video muted controls loop>
                                <source src="{{ attachment.full_url.relative }}" type="{{ attachment.mimetype }}">
                            </video>
                        </a>
                    {% endif %}
                {% endfor %}
                {% for attachment in post.attachments.all %}
                    {% if not attachment.is_image and not attachment.is_video %}
                        <a href="{{ attachment.full_url.relative }}" class="other">
                            <div class="other-label">
                                <i class="fa-solid fa-download"></i> {{ attachment.file_display_name }}
                            </div>
                        </a>
                    {% endif %}
                {% endfor %}
            </div>
        {% endif %}
    </div>

    {% if post.edited %}
        <div class="edited" title="{{ post.edited }}">
            <small>Edited {{ post.edited | timedeltashort }} ago</small>
        </div>
    {% endif %}

    <div class="actions">
        <a title="Replies" href="{% if not post.local and post.url %}{{ post.url }}{% else %}{{ post.urls.view }}{% endif %}">
            <i class="fa-solid fa-reply"></i>
            <span class="like-count">{{ post.stats_with_defaults.replies|default:"0" }}</span>
        </a>
        <a title="Likes" class="no-action">
            <i class="fa-solid fa-star"></i>
            <span class="like-count">{{ post.stats_with_defaults.likes|default:"0" }}</span>
        </a>
        <a title="Boosts" class="no-action">
            <i class="fa-solid fa-retweet"></i>
            <span class="like-count">{{ post.stats_with_defaults.boosts|default:"0" }}</span>
        </a>
        <a title="Menu" class="menu" _="on click or keyup[key is 'Enter'] toggle .enabled on the next <menu/> then halt" role="menuitem" aria-haspopup="menu" tabindex="0">
            <i class="fa-solid fa-bars"></i>
        </a>
        <menu>
            <a href="{{ post.urls.view }}" role="menuitem">
                <i class="fa-solid fa-comment"></i> View Post &amp; Replies
            </a>
            {% if not post.local and post.url %}
                <a href="{{ post.url }}" role="menuitem">
                    <i class="fa-solid fa-arrow-up-right-from-square"></i> See Original
                </a>
            {% endif %}
            {% if request.user.admin %}
                <a href="{{ post.urls.admin_edit }}" role="menuitem">
                    <i class="fa-solid fa-gear"></i> View In Admin
                </a>
            {% endif %}
        </menu>
    </div>

</div>
