{% extends "base.html" %}

{% block title %}Dashboard - AI Chat Archive{% endblock %}

{% block content %}
<div class="container">
    <div class="d-flex justify-content-between align-items-end mb-5">
        <div>
            <span class="badge bg-info bg-opacity-10 text-info mb-2">{{ company.name }}</span>
            <h2 class="fw-bold m-0">Chat Archive</h2>
        </div>
        <div class="text-secondary small">
            Logged in as <span class="text-light fw-bold">{{ user.username }}</span>
        </div>
    </div>

    <!-- Search Section -->
    <div class="glass-card p-4 mb-5">
        <form method="GET" action="{% url 'dashboard' %}" class="row g-3">
            <div class="col-md-10">
                <div class="input-group input-group-lg">
                    <span class="input-group-text bg-transparent border-secondary text-secondary">
                        <i data-lucide="search"></i>
                    </span>
                    <input type="text" name="q" class="form-control bg-transparent border-secondary text-light" 
                           placeholder="Search across all chats..." value="{{ query }}">
                </div>
            </div>
            <div class="col-md-2">
                <button type="submit" class="btn btn-cyan btn-lg w-100">Search</button>
            </div>
        </form>
    </div>

    <!-- Results Section -->
    <div class="row">
        <div class="col-12">
            {% if query %}
                <h5 class="mb-4 text-secondary">Search results for "{{ query }}"</h5>
            {% else %}
                <h5 class="mb-4 text-secondary">Recent Conversations</h5>
            {% endif %}

            {% if chats %}
                <div class="row g-4">
                    {% for chat in chats %}
                    <div class="col-12">
                        <div class="glass-card p-4">
                            <div class="d-flex justify-content-between align-items-start mb-3">
                                <div class="d-flex align-items-center">
                                    <div class="bg-secondary bg-opacity-20 p-2 rounded-3 me-3">
                                        {% if chat.ai_chat_engine == 'ChatGPT' %}
                                            <i data-lucide="message-square" class="text-success"></i>
                                        {% elif chat.ai_chat_engine == 'Bing' %}
                                            <i data-lucide="globe" class="text-info"></i>
                                        {% else %}
                                            <i data-lucide="bot" class="text-warning"></i>
                                        {% endif %}
                                    </div>
                                    <div>
                                        <h5 class="m-0 fw-bold">{{ chat.chat_title }}</h5>
                                        <span class="small text-secondary">{{ chat.ai_chat_engine }} &bull; {{ chat.chat_last_date|date:"M d, Y" }}</span>
                                    </div>
                                </div>
                                <a href="{% url 'chat_detail' chat.pk %}" class="btn btn-outline-secondary btn-sm">
                                    <i data-lucide="external-link" size="16"></i>
                                </a>
                            </div>
                            <div class="chat-content text-secondary">
                                {{ chat.chat_content|truncatewords:50|linebreaks }}
                            </div>
                        </div>
                    </div>
                    {% endfor %}
                </div>
            {% else %}
                <div class="text-center py-5">
                    <i data-lucide="inbox" class="text-secondary mb-3" size="48"></i>
                    <p class="text-secondary">No chats found. Try a different search term or connect an engine.</p>
                </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
