{% load i18n %}
{# List value display template #}

<!-- List display -->
<div class="key-value-display">
    <h3>{% trans 'List Elements' %} ({{ key_data.size }} {% trans 'items' %})</h3>
    
    {% if is_paginated %}
    <!-- Pagination info (without controls) -->
    {% include "admin/dj_redis_panel/key_detail_pagination_info.html" with collection_type="items" %}
    {% endif %}
    
    {% if key_data.value %}
    <table class="key-value-table">
        <thead>
            <tr>
                <th>{% trans 'Index' %}</th>
                <th>{% trans 'Value' %}</th>
                {% if allow_key_edit %}
                <th>{% trans 'Actions' %}</th>
                {% endif %}
            </tr>
        </thead>
        <tbody>
            {% for item in key_data.value %}
            <tr>
                <td><code>{% if is_paginated %}{{ start_index|add:forloop.counter0 }}{% else %}{{ forloop.counter0 }}{% endif %}</code></td>
                <td>
                    {% if allow_key_edit %}
                    <form method="post" style="display: inline-block; width: 100%;">
                        {% csrf_token %}
                        <input type="hidden" name="action" value="update_list_item">
                        <input type="hidden" name="index" value="{% if is_paginated %}{{ start_index|add:forloop.counter0 }}{% else %}{{ forloop.counter0 }}{% endif %}">
                        <div style="display: flex; align-items: center; gap: 5px;">
                            <input type="text" name="new_value" value="{{ item }}" class="inline-edit-input" style="flex: 1;">
                            <button type="submit" class="inline-edit-btn" title="{% trans 'Update item' %}">Save</button>
                        </div>
                    </form>
                    {% else %}
                    <code>{{ item }}</code>
                    {% endif %}
                </td>
                {% if allow_key_edit %}
                <td>
                    <form method="post" style="display: inline;" 
                          onsubmit="return confirm('{% trans 'Are you sure you want to delete this item?' %}');">
                        {% csrf_token %}
                        <input type="hidden" name="action" value="delete_list_item">
                        <input type="hidden" name="index" value="{% if is_paginated %}{{ start_index|add:forloop.counter0 }}{% else %}{{ forloop.counter0 }}{% endif %}">
                        <button type="submit" class="delete-member-btn" title="{% trans 'Delete item' %}">
                            🗑️
                        </button>
                    </form>
                </td>
                {% endif %}
            </tr>
            {% endfor %}
        </tbody>
    </table>
    
    {% if is_paginated %}{% if has_more or total_pages > 1 %}
    <!-- Bottom pagination for lists -->
    {% include "admin/dj_redis_panel/key_detail_pagination.html" with collection_type="list" position="controls" %}
    {% endif %}{% endif %}
    
    {% else %}
    <p class="quiet">{% trans 'List is empty' %}</p>
    {% endif %}
</div>
