{% extends "admin_base.html" %}
{% block extra_head %}
{{ super() }}
<link rel="stylesheet" href="{{ static_url('/static/css/moderation.css') }}">
{% endblock %}
{% block admin_content %}
{% macro decision_table(caption, rows, empty) %}
<table class="admin-table">
    <caption class="sr-only">{{ caption }}</caption>
    <thead>
        <tr>
            <th scope="col">Action</th>
            <th scope="col">Moderator</th>
            <th scope="col">Reason</th>
            <th scope="col">When</th>
        </tr>
    </thead>
    <tbody>
        {% for action in rows %}
        <tr>
            <td>{{ action['action'].replace('_', ' ') }}</td>
            <td>{{ action['actor_name'] }}</td>
            <td>{{ action['reason'] or '-' }}</td>
            <td>{{ local_dt(action['created_at']) }}</td>
        </tr>
        {% else %}
        {% if empty %}<tr><td colspan="4" class="empty-state">{{ empty }}</td></tr>{% endif %}
        {% endfor %}
    </tbody>
</table>
{% endmacro %}
<div class="admin-toolbar">
    <h2>Report {{ report['reason_label'] }}</h2>
    <a href="/admin/moderation" class="admin-btn admin-btn-sm">Back to queue</a>
</div>

<section class="card report-summary">
    <dl class="report-facts">
        <div><dt>Target</dt><dd><a href="{{ report['target_url'] }}">{{ report['target_type'] }} {{ report['target_uid'] }}</a></dd></div>
        <div><dt>Status</dt><dd>{{ report['status'] }}</dd></div>
        <div><dt>Severity</dt><dd><span class="severity-badge severity-{{ report['severity'] }}">{{ report['severity'] }}</span></dd></div>
        <div><dt>Origin</dt><dd>{{ report['origin'] }}</dd></div>
        <div><dt>Reporter</dt><dd>{{ report['reporter_name'] or 'system' }}</dd></div>
        <div><dt>Author</dt><dd>{{ report['owner_name'] or '-' }}</dd></div>
        <div><dt>Filed</dt><dd>{{ local_dt(report['created_at']) }}</dd></div>
        <div><dt>Reports on this target</dt><dd>{{ report['report_count'] }}</dd></div>
    </dl>
    {% if report['detail'] %}
    <p class="report-detail">{{ report['detail'] }}</p>
    {% endif %}
    {% if report['categories'] %}
    <p class="report-categories">Filter categories: {{ report['categories']|join(', ') }}</p>
    {% endif %}
</section>

<section class="card report-decision">
    <h3>Decide</h3>
    {% if not can_remove %}
    <p class="report-hint">Content removal is not available for a {{ report['target_type'] }}; act on the account instead.</p>
    {% endif %}
    <form method="POST" action="/admin/moderation/{{ report['uid'] }}/decide" class="report-form">
        <div class="admin-field">
            <label for="decision-action">Action</label>
            <select id="decision-action" name="action" required>
                {% for action in available_actions %}
                <option value="{{ action }}">{{ action.replace('_', ' ') }}</option>
                {% endfor %}
            </select>
        </div>
        <div class="admin-field">
            <label for="decision-reason">Reason shown to the user</label>
            <input id="decision-reason" name="reason" maxlength="200" placeholder="Breaches the community guidelines on harassment">
        </div>
        <div class="admin-field">
            <label for="decision-hours">Suspension length (hours)</label>
            <input id="decision-hours" name="duration_hours" type="number" min="1" max="8760" value="24">
        </div>
        <div class="admin-field">
            <label for="decision-notes">Internal notes</label>
            <textarea id="decision-notes" name="notes" rows="3" maxlength="2000"></textarea>
        </div>
        <button type="submit" class="btn btn-primary" data-confirm="Apply this moderation decision?">Apply decision</button>
    </form>
    <form method="POST" action="/admin/moderation/{{ report['uid'] }}/status" class="report-form-inline">
        <input type="hidden" name="status" value="acknowledged">
        <button type="submit" class="admin-btn admin-btn-sm">Acknowledge</button>
    </form>
</section>

<section class="card report-history">
    <h3>Decisions on this report</h3>
    {{ decision_table("Moderation decisions recorded against this report", actions, "No decision recorded yet.") }}
</section>

{% if history %}
<section class="card report-history">
    <h3>Author history</h3>
    {{ decision_table("Earlier moderation decisions against this author", history, "") }}
</section>
{% endif %}
{% endblock %}
