{% extends "base.html" %}

{% block title -%}
	{{ report.title }}
{%- endblock %}

{% from "macros/forms.html" import render_field, render_submit_field, render_radio_field, easymde_scripts %}
{% block scriptextra %}
	{{ easymde_scripts() }}
{% endblock %}

{% block content %}

{% set url = url_for("report.view", rid=report.id) %}
<p class="float-end">
	<a class="btn bg-secondary me-2" href="{{ url_for('admin.audit', url=url) }}">View audit log</a>
	<a class="btn bg-secondary" href="{{ url_for('report.edit', rid=report.id) }}">{{ _("Edit") }}</a>
</p>

<p>
	<a class="btn bg-secondary" href="{{ url_for('report.list_all') }}">Back to reports</a>
</p>

<h1>
	{% if report.is_resolved %}
		<span class="badge bg-secondary me-3">
			Closed
		</span>
	{% else %}
		<span class="badge bg-info me-3">
			Open
		</span>
	{% endif %}
	{{ self.title() }}
</h1>

<article class="row">
	<div class="col-md-9">
		<div class="card">
			<div class="card-body markdown">
				{{ report.message | markdown }}
			</div>
		</div>
	</div>

	<aside class="col-md-3 info-sidebar">
		<dl>
			<dt>Category</dt>
			<dd>
				{{ report.category.title }}
			</dd>
		</dl>
		<dl>
			<dt>URL</dt>
			<dd>
				<a href="{{ report.url }}">{{ report.url }}</a>
			</dd>
		</dl>
		<dl>
			<dt>Created At</dt>
			<dd>
				{{  report.created_at | full_datetime }}
			</dd>
		</dl>
		<dl>
			<dt>Reporter</dt>
			<dd>
				{% if report.user %}
				<a href="{{ url_for('users.profile', username=report.user.username) }}">
					{{ report.user.username }}
				</a>
				{% else %}
					Anonymous
				{% endif %}
			</dd>
		</dl>
	</aside>
</article>

{% if report.attachments %}
	<article>
		<h2>Attachments</h2>
		<ul>
			{% for attachment in report.attachments %}
				<li><a href="{{ attachment.url }}">{{ attachment.url }}</a></li>
			{% endfor %}
		</ul>
	</article>
{% endif %}

<article>
	<h2>{% if report.is_resolved %}Reopen report{% else %}Close report{% endif %}</h2>
	<form method="POST" action="">
		<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
		{% if report.is_resolved %}
			<button type="submit" class="btn bg-primary" name="reopen" value="true">{{ _("Reopen") }}</button>
		{% else %}
			<button type="submit" class="btn bg-primary" name="completed" value="true">{{ _("Completed (action taken)") }}</button>
			<button type="submit" class="btn bg-primary" name="removed" value="true">{{ _("Content removed") }}</button>
			<button type="submit" class="btn bg-primary" name="invalid" value="true">{{ _("Invalid / close with no action") }}</button>
		{% endif %}
	</form>
</article>

<article>
	<h2>Thread</h2>
	{% if report.thread %}
		{% from "macros/threads.html" import render_thread %}
		{{ render_thread(report.thread, current_user, form=False) }}
	{% else %}
		<p>
			No thread.
		</p>
	{% endif %}
</article>

{% endblock %}
