{% extends 'admin/layout.twig' %}
{% block title %}Saved replies — Admin{% endblock %}
{% block content %}
    <div class="admin-page-head">
        <h1>Saved replies</h1>
        <p><a class="btn btn-primary" href="{{ app_url('/admin/saved-replies/new') }}">+ New saved reply</a></p>
    </div>

    <table class="data-table">
        <thead>
            <tr><th>Name</th><th>Author</th><th>Visibility</th><th>Updated</th><th></th></tr>
        </thead>
        <tbody>
            {% for r in replies %}
                <tr>
                    <td><a href="{{ app_url('/admin/saved-replies/' ~ r.id ~ '/edit') }}">{{ r.name }}</a></td>
                    <td>{{ r.author_name ?: 'System' }}</td>
                    <td>{% if r.is_global %}<span class="badge badge-success">Global</span>{% else %}<span class="badge">Personal</span>{% endif %}</td>
                    <td>{{ r.updated_at|time_ago }}</td>
                    <td>
                        {% if current_user().role == 'admin' or r.author_id == current_user().id %}
                            <form method="post" action="{{ app_url('/admin/saved-replies/' ~ r.id ~ '/delete') }}" class="inline-form" onsubmit="return confirm('Delete this saved reply?');">
                                {{ csrf_field()|raw }}
                                <button type="submit" class="btn btn-danger small">Delete</button>
                            </form>
                        {% endif %}
                    </td>
                </tr>
            {% else %}
                <tr><td colspan="5" class="muted">No saved replies yet.</td></tr>
            {% endfor %}
        </tbody>
    </table>
{% endblock %}
