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

{% block title %}LLM APIs{% endblock %}

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

{% if apis %}
<div class="overflow-x-auto">
    <table class="table table-zebra w-full">
        <thead>
            <tr>
                <th>Name</th>
                <th>Type</th>
                <th>Base URL</th>
                <th>Active</th>
                <th>Streaming</th>
                <th>Status</th>
                <th>Models</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
        {% for api in apis %}
        <tr>
            <td><a href="{% url 'llm_manager:api_detail' api.pk %}" class="link link-primary font-semibold">{{ api.name }}</a></td>
            <td><span class="badge badge-ghost">{{ api.get_api_type_display }}</span></td>
            <td class="font-mono text-xs max-w-xs truncate">{{ api.base_url }}</td>
            <td>{% if api.is_active %}<span class="badge badge-success badge-sm">Yes</span>{% else %}<span class="badge badge-error badge-sm">No</span>{% endif %}</td>
            <td>{% if api.supports_streaming %}<span class="badge badge-info badge-sm">Yes</span>{% else %}—{% endif %}</td>
            <td>
                {% if api.last_test_status == "success" %}<span class="badge badge-success badge-sm">OK</span>
                {% elif api.last_test_status == "failed" %}<span class="badge badge-error badge-sm">Failed</span>
                {% else %}<span class="badge badge-warning badge-sm">Pending</span>{% endif %}
            </td>
            <td>{{ api.models.count }}</td>
            <td>
                <a href="{% url 'llm_manager:api_edit' api.pk %}" class="btn btn-xs btn-ghost">Edit</a>
                <a href="{% url 'llm_manager:api_delete' api.pk %}" class="btn btn-xs btn-ghost text-error">Delete</a>
            </td>
        </tr>
        {% endfor %}
        </tbody>
    </table>
</div>
{% else %}
<div class="alert alert-info">No APIs configured. <a href="{% url 'llm_manager:api_create' %}" class="link">Add one now</a>.</div>
{% endif %}

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