{% set quarantined = post.quarantined_at and not post.deleted_at %}
{% set pending = (post.approval_status is defined ? post.approval_status : 'approved') == 'pending' and not post.deleted_at %}
<article class="post{% if quarantined and not is_mod %} post-quarantined{% endif %}{% if quarantined and is_mod %} post-quarantined-staff{% endif %}{% if pending %} post-pending{% endif %}"
         id="post-{{ post.id }}"
         data-post-id="{{ post.id }}"
         data-post-op="{{ post.chronological_index|default(loop.index) == 1 ? '1' : '0' }}"
         data-post-seq="{{ post.chronological_index|default(loop.index) }}"
         data-post-quarantined="{{ quarantined ? '1' : '0' }}">
    {% if is_mod and not topic.deleted_at and not is_mod_trash_board|default(false) %}
        <label class="mod-post-check mod-tools-active-only">
            <input type="checkbox" class="mod-post-checkbox" value="{{ post.id }}" aria-label="Select post #{{ post.id }}">
        </label>
    {% endif %}
    <header class="post-meta">
        {% include 'partials/avatar.twig' with { username: post.author_name, avatar_src: post.avatar_src|default(''), avatar_pending_src: post.avatar_pending_src|default(''), avatar_hue: post.avatar_hue|default(210), size: 40 } %}
        <div class="post-meta-text">
            <strong>{% include 'partials/username_link.twig' with { username: post.author_name } %}</strong>
            <time>{{ post.created_at|format_datetime }}</time>
            {% if post.updated_at %}
                <span class="badge badge-muted post-edited-badge" title="{{ trans('topic.last_edited', { time: post.last_edited_at|default(post.updated_at)|format_datetime }) }}">
                    {{ trans('common.edited') }}{% if post.last_editor_username %} {{ trans('common.by') }} {% include 'partials/username_link.twig' with { username: post.last_editor_username } %}{% endif %}
                </span>
            {% endif %}
            {% if is_mod and post.revision_count > 0 %}
                <a class="badge badge-muted post-revision-link mod-tools-active-only" href="/mod/post/{{ post.id }}/revisions">History ({{ post.revision_count }})</a>
            {% endif %}
            {% if quarantined and is_mod %}<span class="badge badge-quarantine">Quarantined</span>{% endif %}
            {% if pending %}<span class="badge badge-pending">Pending approval</span>{% endif %}
            {% if is_mod_trash_board|default(false) and post.restore_board_name %}
                <span class="badge badge-muted">
                    From
                    <a href="/board/{{ post.restore_board_slug }}">{{ post.restore_board_name }}</a>
                    {% if post.trash_restore_topic_id %}
                        · <a href="/topic/{{ post.trash_restore_topic_id }}">{{ post.restore_topic_title }}</a>
                    {% endif %}
                </span>
            {% endif %}
        </div>
    </header>
    {% if quarantined and not is_mod %}
        <div class="post-body post-content post-body--quarantined" role="status" aria-label="{{ trans('topic.under_review_aria') }}">
            <div class="post-quarantine-blur" aria-hidden="true"></div>
            <div class="post-quarantine-overlay">
                <div class="post-quarantine-shield" aria-hidden="true">
                    {% include 'partials/icon.twig' with { name: 'shield', size: 28 } %}
                </div>
                <p class="post-quarantine-label">{{ trans('topic.under_review') }}</p>
                <p class="post-quarantine-hint muted">{{ trans('topic.under_review_hint') }}</p>
            </div>
        </div>
    {% else %}
        <div class="post-body post-content">
            {{ post.body|format_post }}
        </div>
    {% endif %}
    <footer class="post-actions">
        {% include 'partials/post_votes.html.twig' %}
        <div class="post-action-icons" data-staff-feedback>
            {% if post.can_edit %}
                <details class="post-edit-details">
                    <summary class="btn btn-small btn-icon" title="{{ trans('topic.edit_post') }}" aria-label="{{ trans('topic.edit_post') }}">
                        {% include 'partials/icon.twig' with { name: 'edit' } %}
                    </summary>
                    <form method="post" action="/post/{{ post.id }}/edit" class="form post-edit-form">
                        {{ csrf_field() }}
                        <label>
                            {{ trans('topic.edit_message') }}
                            {% include 'partials/composer.twig' with {
                                draft_key: 'edit-post-' ~ post.id,
                                required: true,
                                rows: 8,
                                value: post.body
                            } %}
                        </label>
                        <div class="post-edit-actions">
                            <button type="submit" class="btn btn-small btn-primary">{{ trans('common.save_changes') }}</button>
                        </div>
                    </form>
                </details>
            {% endif %}
            {% if user and not post.deleted_at and not quarantined and not pending %}
                <button type="button" class="btn btn-small btn-icon" title="{{ trans('topic.quote') }}" aria-label="{{ trans('topic.quote_author', { author: post.author_name }) }}"
                        data-quote-post data-quote-author="{{ post.author_name }}" data-quote-body="{{ post.body|slice(0, 2000)|e('html_attr') }}">
                    {% include 'partials/icon.twig' with { name: 'quote' } %}
                </button>
                <details class="report-details">
                    <summary class="btn btn-small btn-icon btn-report" title="{{ trans('topic.report') }}" aria-label="{{ trans('topic.report') }}">
                        {% include 'partials/icon.twig' with { name: 'flag' } %}
                    </summary>
                    <form method="post" action="/report/post/{{ post.id }}" class="form report-form">
                        {{ csrf_field() }}
                        <label>
                            {{ trans('topic.report_reason') }}
                            <select name="reason_code" required>
                                <option value="">{{ trans('common.select') }}</option>
                                {% for code, cat in report_categories %}
                                    <option value="{{ code }}">{{ cat.label }}</option>
                                {% endfor %}
                            </select>
                        </label>
                        <label>
                            {{ trans('topic.report_details') }}
                            <textarea name="reason_detail" rows="2" maxlength="500" placeholder="{{ trans('topic.report_details_placeholder') }}"></textarea>
                        </label>
                        <button type="submit" class="btn btn-small btn-primary btn-icon" title="{{ trans('topic.submit_report') }}" aria-label="{{ trans('topic.submit_report') }}">
                            {% include 'partials/icon.twig' with { name: 'check' } %}
                        </button>
                    </form>
                </details>
            {% endif %}
            {% if is_mod_trash_board|default(false) and is_mod and post.is_restorable_archive|default(false) %}
                <details class="staff-action-panel" data-staff-post="/mod/trash/{{ post.id }}/restore" data-staff-success="trash-item">
                    <summary class="btn btn-small btn-icon" title="Restore post" aria-label="Restore post">
                        {% include 'partials/icon.twig' with { name: 'restore', size: 16 } %}
                    </summary>
                    <div class="staff-action-popover">
                        <p class="staff-action-confirm muted">Restore this post to its original topic?</p>
                        <button type="button" class="btn btn-small btn-primary btn-icon" data-staff-action-submit title="Confirm restore" aria-label="Confirm restore">
                            {% include 'partials/icon.twig' with { name: 'check' } %}
                        </button>
                    </div>
                </details>
            {% endif %}
            {% if is_mod_trash_board|default(false) and is_mod and post.is_trashed_archive|default(false) %}
                <details class="staff-action-panel" data-staff-post="/mod/trash/{{ post.id }}/purge" data-staff-success="trash-item">
                    <summary class="btn btn-small btn-icon btn-danger" title="Delete permanently" aria-label="Delete permanently">
                        {% include 'partials/icon.twig' with { name: 'trash' } %}
                    </summary>
                    <div class="staff-action-popover">
                        <p class="staff-action-confirm muted">Permanently delete this post? This cannot be undone.</p>
                        <button type="button" class="btn btn-small btn-danger btn-icon" data-staff-action-submit title="Confirm delete" aria-label="Confirm delete">
                            {% include 'partials/icon.twig' with { name: 'check' } %}
                        </button>
                    </div>
                </details>
            {% endif %}
        </div>
    </footer>
</article>