{% extends "base/base.html" %}

{% block title %}
<a href="{{ url_for('adm') }}">Panneau d'administration</a> » <h1>Édition du compte  de {{ user.name }}</h1>
{% endblock %}

{% block content %}
<section class="form">
	<a href="{{ url_for('user', username=user.name) }}">Visiter la page de profil de {{ user.name }}</a>
	<form action="{{ url_for('adm_edit_account', user_id=user.id) }}" method="post" enctype="multipart/form-data">
		{{ form.hidden_tag() }}
		<h2>Informations</h2>

		<div>
			{{ form.avatar.label }}
			<div>
				<img class="avatar" src="{{ user.avatar_url }}" />
				{{ form.avatar }}
			</div>
			{% for error in form.avatar.errors %}
			<span class="msgerror">{{ error }}</span>
			{% endfor %}
		</div>

		<div>
			{{ form.username.label }}
			{{ form.username(placeholder=user.name) }}
			{% for error in form.username.errors %}
			<span class="msgerror">{{ error }}</span>
			{% endfor %}
		</div>
		<div>
			{{ form.email.label }}
			{{ form.email(placeholder=user.email) }}
			{% for error in form.email.errors %}
			<span class="msgerror">{{ error }}</span>
			{% endfor %}
		</div>
		<div>
			{{ form.email_confirmed.label }}
			{{ form.email_confirmed(checked=user.email_confirmed) }}
			<div class=desc>{{ form.email_confirmed.description }}</div>
			{% for error in form.email_confirmed.errors %}
			<span class="msgerror">{{ error }}</span>
			{% endfor %}
		</div>
		<div>
			{{ form.password.label }}
			<div class=desc>{{ form.password.description }}</div>
			{{ form.password(placeholder='************') }}
			<progress class="entropy" value="0" max="100"></progress>
			{% for error in form.password.errors %}
			<span class="msgerror">{{ error }}</span>
			{% endfor %}
		</div>

		<h2>Participation</h2>
		<div>
			{{ form.xp.label }}
			{{ form.xp(placeholder=user.xp) }}
			{% for error in form.xp.errors %}
			<span class="msgerror">{{ error }}</span>
			{% endfor %}
		</div>

		<h2>À propos</h2>
		<div>
			{{ form.title.label }}
			{{ form.title }}
			{% for error in form.title.errors %}
			<span class="msgerror">{{ error }}</span>
			{% endfor %}
		</div>
		<div>
			{{ form.birthday.label }}
			{{ form.birthday(value=user.birthday) }}
			{% for error in form.birthday.errors %}
			<span class="msgerror">{{ error }}</span>
			{% endfor %}
		</div>
		<div>
			{{ form.signature.label }}
			<textarea id="{{ form.signature.name }}" name="{{ form.signature.name }}">{{ user.signature }}</textarea>
			{% for error in form.signature.errors %}
			<span class="msgerror">{{ error }}</span>
			{% endfor %}
		</div>
		<div>
			{{ form.biography.label }}
			<textarea id="{{ form.biography.name }}" name="{{ form.biography.name }}">{{ user.bio }}</textarea>
			{% for error in form.biography.errors %}
			<span class="msgerror">{{ error }}</span>
			{% endfor %}
		</div>

		<h2>Préférences</h2>
		<div>
			{{ form.newsletter.label }}
			{{ form.newsletter(checked=user.newsletter) }}
			<div class=desc>{{ form.newsletter.description }}</div>
			{% for error in form.newsletter.errors %}
			<span class="msgerror">{{ error }}</span>
			{% endfor %}
		</div>
		<div>{{ form.submit(class_="bg-ok") }}</div>
	</form>

	<hr>

	<form action="{{ url_for('adm_edit_account', user_id=user.id) }}" method="post">
		{{ trophy_form.hidden_tag() }}
		<h2>Trophées</h2>
		<div class="trophies">
			{% for id, t in trophy_form.trophies.items() %}
				<div class="trophy form-disabled">
					{{ trophy_form[id](checked=id in trophies_owned) }}
					<img src="{{ url_for('static', filename='images/trophies/'+slugify(t.name))+'.png' }}">
					<div>
						<em>{{ t.name }}</em>
						<span>{{ t.description }}</span>
					</div>
				</div>
			{% endfor %}
		</div>
		<div>{{ trophy_form.submit(class_="bg-ok") }}</div>
	</form>

	<hr>

	<form action="{{ url_for('adm_edit_account', user_id=user.id) }}" method="post">
		{{ group_form.hidden_tag() }}
		<h2>Groupes</h2>
		<div class="groups-panel flex-grid fg3">
			{% for id, g in group_form.groups.items() %}
				<div>
					{{ group_form[id](checked=id in groups_owned) }}
					{{ group_form[id].label(style=g.css) }}
				</div>
			{% endfor %}
		</div>
		<div>{{ group_form.submit(class_="bg-ok") }}</div>
	</form>

	<hr>

	<h2 style="margin-top:30px;">Supprimer le compte</h2>
	<a href="{{ url_for('adm_delete_account', user_id=user.id) }}" class="button bg-error">Supprimer le compte</a>

</section>
{% endblock %}
