{% extends "themis/base.html" %}

{% block title %}Dashboard — Mnemosyne{% endblock %}

{% block content %}
<div class="mb-6">
    <h1 class="text-3xl font-bold">Dashboard</h1>
    <p class="text-base-content/70">Welcome back, {{ user.username }}.</p>
</div>

<!-- Overview stats -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-8">
    <a href="{% url 'library:library-list' %}" class="stat bg-base-200 rounded-box shadow hover:bg-base-300 transition">
        <div class="stat-title">Libraries</div>
        <div class="stat-value text-primary">{% if library_count is not None %}{{ library_count }}{% else %}—{% endif %}</div>
        <div class="stat-desc">{% if library_count is None %}Neo4j offline{% else %}Content collections{% endif %}</div>
    </a>
    <a href="{% url 'llm_manager:api_list' %}" class="stat bg-base-200 rounded-box shadow hover:bg-base-300 transition">
        <div class="stat-title">Active APIs</div>
        <div class="stat-value text-secondary">{{ api_count }}</div>
        <div class="stat-desc">LLM providers</div>
    </a>
    <a href="{% url 'llm_manager:model_list' %}" class="stat bg-base-200 rounded-box shadow hover:bg-base-300 transition">
        <div class="stat-title">LLM Models</div>
        <div class="stat-value text-accent">{{ model_count }}</div>
        <div class="stat-desc">Available models</div>
    </a>
    <a href="{% url 'themis:key-list' %}" class="stat bg-base-200 rounded-box shadow hover:bg-base-300 transition">
        <div class="stat-title">Your Keys</div>
        <div class="stat-value">🔑</div>
        <div class="stat-desc">Manage API keys</div>
    </a>
</div>

<!-- System models -->
<div class="mb-8">
    <h2 class="text-xl font-semibold mb-3">System Models</h2>
    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
        <div class="card bg-base-200 shadow">
            <div class="card-body py-4">
                <h3 class="text-sm font-semibold text-base-content/60">Embedding Model</h3>
                {% if system_embedding %}
                    <p class="font-mono">{{ system_embedding.name }}</p>
                    <p class="text-xs text-base-content/50">{{ system_embedding.api.name }}{% if system_embedding.vector_dimensions %} · {{ system_embedding.vector_dimensions }}d{% endif %}</p>
                {% else %}
                    <p class="text-warning text-sm">Not configured — set via Django admin</p>
                {% endif %}
            </div>
        </div>
        <div class="card bg-base-200 shadow">
            <div class="card-body py-4">
                <h3 class="text-sm font-semibold text-base-content/60">Chat Model</h3>
                {% if system_chat %}
                    <p class="font-mono">{{ system_chat.name }}</p>
                    <p class="text-xs text-base-content/50">{{ system_chat.api.name }}</p>
                {% else %}
                    <p class="text-warning text-sm">Not configured — set via Django admin</p>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<!-- Quick actions -->
<div>
    <h2 class="text-xl font-semibold mb-3">Quick Actions</h2>
    <div class="flex flex-wrap gap-3">
        <a href="{% url 'library:search' %}" class="btn btn-primary btn-sm">Search Knowledge</a>
        <a href="{% url 'library:library-create' %}" class="btn btn-secondary btn-sm">New Library</a>
        <a href="{% url 'llm_manager:api_create' %}" class="btn btn-secondary btn-sm">Add LLM API</a>
        <a href="{% url 'themis:key-create' %}" class="btn btn-accent btn-sm">Add API Key</a>
        <a href="{% url 'themis:profile-settings' %}" class="btn btn-ghost btn-sm">Profile Settings</a>
        {% if user.is_staff %}
        <a href="/admin/" class="btn btn-ghost btn-sm">Django Admin</a>
        {% endif %}
    </div>
</div>
{% endblock %}
