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

{% block title %}{% if editing %}Edit Collection{% else %}New Collection{% endif %} — {{ themis_app_name }}{% endblock %}

{% block content %}
<div class="mb-4">
    {% if library %}
    <a href="{% url 'library:library-detail' uid=library.uid %}" class="btn btn-ghost btn-sm">← {{ library.name }}</a>
    {% else %}
    <a href="{% url 'library:library-list' %}" class="btn btn-ghost btn-sm">← Libraries</a>
    {% endif %}
</div>

<h1 class="text-3xl font-bold mb-6">
    {% if editing %}Edit Collection: {{ collection.name }}{% else %}New Collection{% endif %}
</h1>
{% if library %}<p class="opacity-60 mb-4">In library: {{ library.name }}</p>{% endif %}

<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">Description</span></label>
            {{ form.description }}
        </div>
    </div>
    <div class="flex gap-2 mt-6">
        <button type="submit" class="btn btn-primary">
            {% if editing %}Save Changes{% else %}Create Collection{% endif %}
        </button>
        {% if library %}
        <a href="{% url 'library:library-detail' uid=library.uid %}" class="btn btn-ghost">Cancel</a>
        {% else %}
        <a href="{% url 'library:library-list' %}" class="btn btn-ghost">Cancel</a>
        {% endif %}
    </div>
</form>
{% endblock %}
