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

{% block title %}Edit {{ token.name }} — {{ themis_app_name }}{% endblock %}

{% block content %}
<div class="max-w-2xl mx-auto">
    <h1 class="text-2xl font-bold mb-6">Edit Token: {{ token.name }}</h1>

    <div class="alert alert-info mb-6">
        <span>You can edit metadata below. The token value itself cannot be changed — generate a new token if needed.</span>
    </div>

    <form method="post" action="{% url 'mcp_server:token-edit' pk=token.pk %}">
        {% csrf_token %}

        <div class="card bg-base-200 mb-6">
            <div class="card-body">
                <div class="form-control">
                    <label class="label" for="id_name">
                        <span class="label-text">Name</span>
                    </label>
                    {{ form.name }}
                </div>
                <div class="form-control mt-4">
                    <label class="label cursor-pointer justify-start gap-3">
                        {{ form.is_active }}
                        <span class="label-text">Active</span>
                    </label>
                </div>
                <div class="form-control mt-4">
                    <label class="label" for="id_expires_at">
                        <span class="label-text">Expires at (optional)</span>
                    </label>
                    {{ form.expires_at }}
                </div>
            </div>
        </div>

        <details class="card bg-base-200 mb-6"{% if form.allowed_tools.value or form.allowed_libraries.value %} open{% endif %}>
            <summary class="card-body cursor-pointer">
                <h2 class="card-title text-lg">Restrictions (optional)</h2>
                <p class="text-sm opacity-70">
                    These restrictions apply only when the token is used by an MCP
                    tool client (e.g. Claude Desktop). They are ignored by the
                    Daedalus REST API and the Mnemosyne web session.
                </p>
            </summary>
            <div class="card-body pt-0">
                <h3 class="font-semibold mt-2">Allowed Tools</h3>
                <p class="text-sm opacity-60 mb-2">{{ form.allowed_tools.help_text }}</p>
                <div class="space-y-1">
                    {% for choice in form.allowed_tools %}
                    <label class="label cursor-pointer justify-start gap-3">
                        {{ choice.tag }}
                        <span class="label-text font-mono">{{ choice.choice_label }}</span>
                    </label>
                    {% endfor %}
                </div>
            </div>
        </details>

        <div class="flex justify-between">
            <a href="{% url 'mcp_server:token-detail' pk=token.pk %}" class="btn btn-ghost">Cancel</a>
            <button type="submit" class="btn btn-primary">Save Changes</button>
        </div>
    </form>
</div>
{% endblock %}
