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

{% block title %}Edit {{ key.display_name }} — {{ themis_app_name }}{% endblock %}

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

    <div class="alert alert-info mb-6">
        <span>You can edit the key metadata below. The encrypted key value cannot be changed — delete and re-add the key if needed.</span>
    </div>

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

        <div class="card bg-base-200 mb-6">
            <div class="card-body">
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div class="form-control">
                        <label class="label" for="id_service_name">
                            <span class="label-text">Service Name</span>
                        </label>
                        {{ form.service_name }}
                    </div>
                    <div class="form-control">
                        <label class="label" for="id_key_type">
                            <span class="label-text">Key Type</span>
                        </label>
                        {{ form.key_type }}
                    </div>
                </div>
                <div class="form-control mt-4">
                    <label class="label" for="id_label">
                        <span class="label-text">Label</span>
                    </label>
                    {{ form.label }}
                </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>
        </div>

        <div class="card bg-base-200 mb-6">
            <div class="card-body">
                <h2 class="card-title text-lg">Documentation</h2>
                <div class="form-control">
                    <label class="label" for="id_instructions">
                        <span class="label-text">Instructions</span>
                    </label>
                    {{ form.instructions }}
                </div>
                <div class="form-control mt-4">
                    <label class="label" for="id_help_url">
                        <span class="label-text">Help URL</span>
                    </label>
                    {{ form.help_url }}
                </div>
            </div>
        </div>

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