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

{% block title %}{{ library.name }} — {{ themis_app_name }}{% endblock %}

{% block content %}
<div class="mb-4">
    <a href="{% url 'library:library-list' %}" class="btn btn-ghost btn-sm">← Libraries</a>
</div>

<div class="flex justify-between items-start mb-6">
    <div>
        <h1 class="text-3xl font-bold">{{ library.name }}</h1>
        <div class="badge badge-primary mt-2">{{ library.library_type }}</div>
        {% if library.description %}
        <p class="mt-3 opacity-80">{{ library.description }}</p>
        {% endif %}
    </div>
    <div class="flex gap-2">
        <a href="{% url 'library:library-edit' uid=library.uid %}" class="btn btn-sm btn-outline">Edit</a>
        <a href="{% url 'library:library-delete' uid=library.uid %}" class="btn btn-sm btn-error btn-outline">Delete</a>
    </div>
</div>

<!-- Content-Type Configuration -->
<div class="collapse collapse-arrow bg-base-200 mb-6">
    <input type="checkbox" />
    <div class="collapse-title font-medium">Content-Type Configuration</div>
    <div class="collapse-content">
        <div class="grid grid-cols-1 gap-4">
            {% if library.embedding_instruction %}
            <div>
                <h4 class="font-semibold text-sm opacity-60">Embedding Instruction</h4>
                <p class="text-sm mt-1">{{ library.embedding_instruction }}</p>
            </div>
            {% endif %}
            {% if library.reranker_instruction %}
            <div>
                <h4 class="font-semibold text-sm opacity-60">Reranker Instruction</h4>
                <p class="text-sm mt-1">{{ library.reranker_instruction }}</p>
            </div>
            {% endif %}
            {% if library.llm_context_prompt %}
            <div>
                <h4 class="font-semibold text-sm opacity-60">LLM Context Prompt</h4>
                <p class="text-sm mt-1">{{ library.llm_context_prompt }}</p>
            </div>
            {% endif %}
        </div>
    </div>
</div>

<!-- Collections -->
<div class="flex justify-between items-center mb-4">
    <h2 class="text-xl font-bold">Collections</h2>
    <a href="{% url 'library:collection-create' library_uid=library.uid %}" class="btn btn-sm btn-primary">
        + New Collection
    </a>
</div>

{% if collections %}
<div class="overflow-x-auto">
    <table class="table table-zebra w-full">
        <thead>
            <tr>
                <th>Name</th>
                <th>Description</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            {% for col in collections %}
            <tr>
                <td>
                    <a href="{% url 'library:collection-detail' uid=col.uid %}" class="link link-hover font-medium">
                        {{ col.name }}
                    </a>
                </td>
                <td class="opacity-70">{{ col.description|truncatewords:15 }}</td>
                <td>
                    <a href="{% url 'library:collection-detail' uid=col.uid %}" class="btn btn-xs btn-ghost">View</a>
                    <a href="{% url 'library:collection-edit' uid=col.uid %}" class="btn btn-xs btn-ghost">Edit</a>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% else %}
<div class="text-center py-8 opacity-60">
    <p>No collections in this library yet.</p>
</div>
{% endif %}
{% endblock %}
