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

{% block title %}LLM Models{% endblock %}

{% block content %}
<div class="flex justify-between items-center mb-6">
    <h1 class="text-2xl font-bold">LLM Models</h1>
    <a href="{% url 'llm_manager:model_create' %}" class="btn btn-primary btn-sm">Add Model</a>
</div>

<!-- Filter by API -->
<div class="mb-4 flex gap-2 items-center">
    <span class="font-semibold text-sm">Filter API:</span>
    <a href="{% url 'llm_manager:model_list' %}" class="btn btn-xs {% if not selected_api %}btn-primary{% else %}btn-ghost{% endif %}">All</a>
    {% for api in apis %}
    <a href="{% url 'llm_manager:model_list' %}?api={{ api.pk }}" class="btn btn-xs {% if selected_api == api.pk|slugify %}btn-primary{% else %}btn-ghost{% endif %}">{{ api.name }}</a>
    {% endfor %}
</div>

{% if models %}
<div class="overflow-x-auto">
    <table class="table table-zebra w-full">
        <thead>
            <tr>
                <th>Name</th>
                <th>API</th>
                <th>Type</th>
                <th>Context</th>
                <th>Dims</th>
                <th>$/1K In</th>
                <th>$/1K Out</th>
                <th>Active</th>
                <th>System</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
        {% for m in models %}
        <tr>
            <td><a href="{% url 'llm_manager:model_detail' m.pk %}" class="link link-primary font-mono text-sm">{{ m.name }}</a></td>
            <td class="text-sm">{{ m.api.name }}</td>
            <td><span class="badge badge-ghost badge-sm">{{ m.get_model_type_display }}</span></td>
            <td>{{ m.context_window|default:"—" }}</td>
            <td>{{ m.vector_dimensions|default:"—" }}</td>
            <td class="text-xs">${{ m.input_cost_per_1k }}</td>
            <td class="text-xs">${{ m.output_cost_per_1k }}</td>
            <td>{% if m.is_active %}<span class="badge badge-success badge-xs">✓</span>{% else %}<span class="badge badge-error badge-xs">✗</span>{% endif %}</td>
            <td>
                {% if m.is_system_embedding_model %}<span class="badge badge-sm badge-success">Embed</span>{% endif %}
                {% if m.is_system_chat_model %}<span class="badge badge-sm badge-info">Chat</span>{% endif %}
                {% if m.is_system_reranker_model %}<span class="badge badge-sm badge-warning">Rerank</span>{% endif %}
            </td>
            <td>
                <a href="{% url 'llm_manager:model_edit' m.pk %}" class="btn btn-xs btn-ghost">Edit</a>
            </td>
        </tr>
        {% endfor %}
        </tbody>
    </table>
</div>
{% else %}
<div class="alert alert-info">No models found.</div>
{% endif %}

<div class="mt-4">
    <a href="{% url 'llm_manager:dashboard' %}" class="btn btn-ghost btn-sm">&larr; Dashboard</a>
</div>
{% endblock %}
