{% load i18n %}
{% load aa_forum %}

<div id="message-{{ message.id }}" class="card card-default mb-3">
    {% aa_forum_template_variable message_author = message.user_created %}

    <div class="card-body">
        <div class="aa-forum-message">
            <div class="d-none d-sm-block m-sm-3 m-md-0">
                {% include "aa_forum/partials/forum/topic/message-author.html" %}
            </div>

            <div class="aa-forum-message-wrapper m-3">
                <div class="aa-forum-message-header row mb-3">
                    <div class="d-lg-none d-md-none d-sm-none">
                        {% include "aa_forum/partials/forum/topic/message-author.html" %}
                    </div>

                    <div class="aa-forum-message-keyinfo col-md-6">
                        <a
                            href="{% url 'aa_forum:forum_message' message.topic.board.category.slug message.topic.board.slug message.topic.slug message.pk %}"
                            title="{{ board_latest_topic.subject }}"
                            data-bs-tooltip="aa-forum"
                        >
                            {% if topic.first_message.pk != message.pk %}
                                {% translate "Re:" %}
                            {% endif %}

                            {{ topic.subject }}
                        </a><br>
                        <small>« <b>{% translate "on:" %}</b> {{ message.time_posted|aa_forum_time }} »</small>
                    </div>

                    <div class="col-md-6">
                        {% if not search_term %}
                            <div class="float-end">
                                <button
                                    class="btn btn-aa-forum-topic-moderation btn-sm btn-aa-forum-copy-to-clipboard"
                                    title="{% translate 'Copy message link to clipboard' %}"
                                    data-bs-tooltip="aa-forum"
                                    data-clipboard-text="{{ SITE_URL }}{% url 'aa_forum:forum_message' message.topic.board.category.slug message.topic.board.slug message.topic.slug message.pk %}"
                                >
                                    <i class="fa-regular fa-copy"></i>
                                </button>

                                {% if message_author == request.user or perms.aa_forum.manage_forum %}
                                    <a
                                        id="aa-forum-btn-modify-message-{{ message.pk }}"
                                        href="{% url 'aa_forum:forum_message_modify' topic.board.category.slug topic.board.slug topic.slug message.pk %}"
                                        class="btn btn-aa-forum-topic-moderation btn-sm"
                                        title="{% translate 'Modify message' %}"
                                        data-bs-tooltip="aa-forum"
                                    >
                                        <i class="fa-solid fa-pencil"></i>
                                    </a>

                                    <button
                                        class="btn btn-aa-forum-topic-moderation btn-sm"
                                        title="{% translate 'Delete message' %}"
                                        data-bs-tooltip="aa-forum"
                                        data-bs-toggle="modal"
                                        data-bs-target="#delete-message-{{ message.pk }}"
                                    >
                                        <i class="fa-regular fa-trash-can"></i>
                                    </button>
                                {% endif %}
                            </div>

                            {% include "aa_forum/modals/forum/topic/message-delete.html" %}
                        {% endif %}
                    </div>
                </div>

                <div class="aa-forum-message-body pt-3">
                    <div class="aa-forum-message-body-inner">
                        <div class="ck ck-content">
                            {% if search_term %}
                                {{ message.message|aa_forum_highlight_search_term:search_term }}
                            {% else %}
                                {{ message.message|safe }}
                            {% endif %}
                        </div>
                    </div>

                    {% if message.user_updated %}
                        <div class="aa-forum-message-body-last-edited text-muted small">
                            « {% translate "Last modified:" %} {{ message.time_modified|aa_forum_time }} by {{ message.user_updated|aa_forum_main_character_name }} »
                        </div>
                    {% endif %}

                    {% if message_author.aa_forum_user_profile %}
                        {% if message_author.aa_forum_user_profile.signature %}
                            <div class="aa-forum-message-body-author-signature text-muted small hidden-xs pt-3">
                                <div class="ck ck-content">
                                    {{ message_author.aa_forum_user_profile.signature|safe }}
                                </div>
                            </div>
                        {% endif %}
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
