{% extends 'django_spire/ai/chat/message/message.html' %}

{% load spire_ai_chat_tags %}

{% block message_content %}
    <div class="row">
        <div class="col ai-message-content">
            {{ message_intel.answer_intel.answer|render_markdown }}
        </div>
    </div>

    {% if message_intel.entries_intel.unique %}
        <div class="mt-2 pt-2 border-top" x-data="{show_resources: false}">
            <span class="text-muted cursor-pointer" style="font-size: 0.8rem;" x-on:click="show_resources = !show_resources">
                <i class="bi bi-caret-right" x-show="!show_resources"></i>
                <i class="bi bi-caret-down" x-show="show_resources"></i>
                Sources
            </span>

            <ul class="my-0 me-3" x-show="show_resources">
                {% for entry_intel in message_intel.entries_intel.unique %}
                    {% if entry_intel.entry and entry_intel.entry.id %}
                        <li class="pb-1">
                            <a href="{% url 'django_spire:knowledge:entry:version:page:editor' pk=entry_intel.entry.id %}?show_sub_nav=false&block_id={{ entry_intel.relevant_block_id }}"
                               target="_blank">
                                {{ entry_intel.relevant_heading_text }}
                            </a>
                        </li>
                    {% else %}
                        <li class="pb-1 text-muted">
                            {{ entry_intel.relevant_heading_text }} (source unavailable)
                        </li>
                    {% endif %}
                {% endfor %}
            </ul>
        </div>
    {% endif %}
{% endblock %}
