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

{% block title %}{% if editing %}Edit Library{% else %}New Library{% endif %} — {{ 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>

<h1 class="text-3xl font-bold mb-6">
    {% if editing %}Edit Library: {{ library.name }}{% else %}New Library{% endif %}
</h1>

<form method="post" class="max-w-2xl">
    {% csrf_token %}
    <div class="space-y-4">
        <div class="form-control">
            <label class="label"><span class="label-text font-medium">Name</span></label>
            {{ form.name }}
            {% if form.name.errors %}<p class="text-error text-sm mt-1">{{ form.name.errors.0 }}</p>{% endif %}
        </div>

        <div class="form-control">
            <label class="label"><span class="label-text font-medium">Library Type</span></label>
            {{ form.library_type }}
        </div>

        <div class="form-control">
            <label class="label"><span class="label-text font-medium">Description</span></label>
            {{ form.description }}
        </div>

        <div class="divider">Content-Type Configuration</div>

        <div class="form-control">
            <label class="label"><span class="label-text font-medium">Embedding Instruction</span></label>
            {{ form.embedding_instruction }}
            <label class="label"><span class="label-text-alt opacity-60">Leave blank to use default for the selected library type</span></label>
        </div>

        <div class="form-control">
            <label class="label"><span class="label-text font-medium">Reranker Instruction</span></label>
            {{ form.reranker_instruction }}
        </div>

        <div class="form-control">
            <label class="label"><span class="label-text font-medium">LLM Context Prompt</span></label>
            {{ form.llm_context_prompt }}
        </div>
    </div>

    <div class="flex gap-2 mt-6">
        <button type="submit" class="btn btn-primary">
            {% if editing %}Save Changes{% else %}Create Library{% endif %}
        </button>
        <a href="{% url 'library:library-list' %}" class="btn btn-ghost">Cancel</a>
    </div>
</form>
{% endblock %}
