{% extends "layout.html" %}
{% block title %}Edit {{ torrent.display_name }} :: {{ config.SITE_NAME }}{% endblock %}
{% block body %}
{% from "_formhelpers.html" import render_field %}
{% from "_formhelpers.html" import render_markdown_editor %}

{% set torrent_url = url_for('torrents.view', torrent_id=torrent.id) %}
<h1>
	Edit Torrent <a href="{{ torrent_url }}">#{{torrent.id}}</a>
	{% if (torrent.user != None) and (torrent.user != g.user) %}
	(by <a href="{{ url_for('users.view_user', user_name=torrent.user.username) }}">{{ torrent.user.username }}</a>)
	{% endif %}
</h1>

<form method="POST" enctype="multipart/form-data">
	{{ form.csrf_token }}

	<div class="row">
		<div class="col-md-6">
		{{ render_field(form.display_name, class_='form-control', placeholder='Display name') }}
		</div>
		<div class="col-md-4">
		{{ render_field(form.category, class_='form-control')}}
		</div>
	</div>
	<div class="row">
		<div class="col-md-6">
		{{ render_field(form.information, class_='form-control', placeholder='Your website or IRC channel') }}
		</div>
		<div class="col-md-6">
			<label class="control-label">Torrent flags</label><br>
			<div class="btn-group" data-toggle="buttons">
				{# Only allow changing anonymous status when an uploader exists #}
				{% if torrent.uploader_id %}
				<label class="btn btn-default {% if torrent.anonymous %}active{% endif %}" title="Upload torrent anonymously (don't display your username)">
					{{ form.is_anonymous }}
					<span class="glyphicon glyphicon-check"></span>
					<span class="glyphicon glyphicon-unchecked"></span>
					Anonymous
				</label>
				{% endif %}
				<label class="btn btn-grey {% if torrent.hidden %}active{% endif %}" title="Hide torrent from listing">
					{{ form.is_hidden }}
					<span class="glyphicon glyphicon-check"></span>
					<span class="glyphicon glyphicon-unchecked"></span>
					Hidden
				</label>
			</div>
			<div class="hidden-xl"><br></div>
			<div class="btn-group" data-toggle="buttons">
				<label class="btn btn-danger {% if torrent.remake %}active{% endif %}" title="This torrent is derived from another release">
					{{ form.is_remake }}
					<span class="glyphicon glyphicon-check"></span>
					<span class="glyphicon glyphicon-unchecked"></span>
					Remake
				</label>
				<label class="btn btn-warning {% if torrent.complete %}active{% endif %}" title="This torrent is a complete batch (eg. season)">
					{{ form.is_complete }}
					<span class="glyphicon glyphicon-check"></span>
					<span class="glyphicon glyphicon-unchecked"></span>
					Complete
				</label>
				{% if g.user.is_trusted %}
				<label class="btn btn-success {% if torrent.trusted %}active{% endif %}" title="Mark torrent trusted">
					{{ form.is_trusted }}
					<span class="glyphicon glyphicon-check"></span>
					<span class="glyphicon glyphicon-unchecked"></span>
					Trusted
				</label>
				{% endif %}
			</div>
		</div>
	</div>

	<div class="row">
		<div class="col-md-12">
			{{ render_markdown_editor(form.description, field_name='description') }}
		</div>
	</div>

	<div class="row">
		<div class="form-group col-md-6">
			<input type="submit" value="Save Changes" class="btn btn-primary">
		</div>
	</div>
</form>
<hr>

<div class="row">
	<div class="col-md-5"">
		<div class="panel panel-danger">
			<div class="panel-heading">
				<h3 class="panel-title">Danger Zone</h3>
			</div>
			<div class="panel-body">
				<form method="POST" action="{{ url_for('torrents.delete', torrent_id=torrent.id) }}">
					{{ delete_form.csrf_token }}

					{% if not torrent.deleted %}
					<p class="lead">
						Delete torrent.
						{{ delete_form.delete(class="btn btn-danger pull-right") }}
					</p>
					<p>
						Deleted torrents are retained for backup purposes.<br>
						You (or someone else) will be able to reupload the torrent.
					</p>

					{% if g.user.is_moderator %}
					<hr>
					<p class="lead">
						Delete and ban torrent.
						{{ delete_form.ban(class="btn btn-danger pull-right") }}
					</p>
					<p>
						Soft deletes the torrent and disallows reuploading it.
					</p>
					{% endif %}
					{% else %}
					<p>This torrent is <strong>deleted</strong>{% if torrent.banned %} and <strong>banned</strong>{% endif %}.</p>
					<p class="lead">
						Undelete{% if torrent.banned %} and unban{% endif %} torrent.
						{% if torrent.banned %}
						{{ delete_form.undelete(value="Undelete & Unban", class="btn btn-info pull-right") }}
						{% else %}
						{{ delete_form.undelete(class="btn btn-info pull-right") }}
						{% endif %}
					</p>
					<p>
						Undeletes{% if torrent.banned %} and unbans{% endif %} this torrent.
					</p>

					{% if torrent.banned %}
					<hr>
					<p class="lead">
						Unban torrent.
						{{ delete_form.unban(class="btn btn-info pull-right") }}
					</p>
					<p>
						Unbans torrent without undeleting it.<br>
						Allows reuploading this torrent again.
					</p>
					{% else%}
					<hr>
					<p class="lead">
						Ban torrent.
						{{ delete_form.ban(value="Ban", class="btn btn-danger pull-right") }}
					</p>
					<p>
						Bans the torrent.<br>
						Disallows reuploading this torrent.
					</p>
					{% endif %}

					{% endif %}
				</form>
			</div>
		</div>
	</div>
</div>

{% endblock %}