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

{% block title %}Generate MCP Token — {{ themis_app_name }}{% endblock %}

{% block content %}
<div class="max-w-2xl mx-auto">
    <h1 class="text-2xl font-bold mb-6">Generate MCP Token</h1>

    <div class="alert alert-info mb-6">
        <span>The token will be displayed once after creation. Save it before leaving the page — it cannot be recovered.</span>
    </div>

    <form method="post" action="{% url 'mcp_server:mcp-token-create' %}">
        {% 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 }}
                    <label class="label">
                        <span class="label-text-alt opacity-60">A friendly label so you can identify this token later (e.g. “Claude Desktop”).</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 }}
                    <label class="label">
                        <span class="label-text-alt opacity-60">{{ form.expires_at.help_text }}</span>
                    </label>
                </div>
            </div>
        </div>

        <div class="card bg-base-200 mb-6">
            <div class="card-body">
                <h2 class="card-title text-lg">Allowed Tools</h2>
                <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>
                {% if form.allowed_tools.errors %}
                <div class="text-error text-sm mt-2">{{ form.allowed_tools.errors }}</div>
                {% endif %}
            </div>
        </div>

        <div class="flex justify-between">
            <a href="{% url 'mcp_server:mcp-token-list' %}" class="btn btn-ghost">Cancel</a>
            <button type="submit" class="btn btn-primary">Generate Token</button>
        </div>
    </form>
</div>
{% endblock %}
