{% extends "base" %}
{% import "macros/form" as form %}
{% block title %}Settings - {% endblock title %}
{% block main %}
<h2>Your settings</h2>

<div class="fields raised">
	<form method="post" action="/account/settings/common">

		{% if prev_common.form_errors | length > 0 %}
		<div class="form-error">
			<h4>Some errors were encountered...</h4>

			<ul>
				{% for err in prev_common.form_errors %}
				<li>{{err}}</li>
				{% endfor %}
			</ul>
		</div>
		{% endif %}

		<div>
			<p class="heading"><label for="username">Username</label></p>
			<input type="text" id="username" name="username" maxlength="256" placeholder="{{user.username}}"
				{{form::value(ctx=prev_common, name="username" )}}>
			{{form::error(ctx=prev_common, name="username")}}
			<p class="note">
				Reminder: your username is your login ID.
				If you change it, don't forget to use the new one to log in.
			</p>
		</div>

		<div>
			<p class="heading"><label for="email">Recovery email</label></p>
			<input type="email" id="email" name="email" maxlength="254" placeholder="{{user.email}}"
				{{form::value(ctx=prev_common, name="email" )}}>
			{{form::error(ctx=prev_common, name="email")}}
		</div>

		<button type="submit">Save those changes</button>
	</form>
</div>

<div class="fields raised">
	<form method="post" action="/account/settings/password">
		<div>
			<p class="heading"><label for="old_password">Current password</label></p>
			<input type="password" id="old_password" name="old_password" minlength="8" {{form::value(ctx=prev_common,
				name="old_password" )}}>
			{{form::error(ctx=prev_password, name="old_password")}}
		</div>
		<div>
			<p class="heading"><label for="password">New password</label></p>
			<input type="password" id="password" name="password" minlength="8" {{form::value(ctx=prev_common,
				name="password" )}}>
			{{form::error(ctx=prev_password, name="password")}}
		</div>
		<div>
			<p class="heading"><label for="confirm_password">Confirm the password</label></p>
			<input type="password" id="confirm_password" name="confirm_password" minlength="8"
				{{form::value(ctx=prev_common, name="confirm_password" )}}>
			{{form::error(ctx=prev_password, name="confirm_password")}}
		</div>

		<button type="submit">Change your password</button>
	</form>
</div>

<section id="data-export">
	<h3>Exporting your data</h3>

	<p>You can export all your account's data using this button.</p>
	<p>It will be provided in a JSON file whose structure is documented.</p>
	<!-- TODO: Link structure documentation. -->
	<a href="/account/data_dump" class="btn">Export all my data</a>
</section>

<section id="account-delete">
	<h3>Deleting your account</h3>

	<p>You can delete your account by clicking on the button below.</p>
	<p>
		Deleting your account will also delete all tags registered to you
		while locking them out of registration for anyone else for a certain time period.
	</p>
	<p>This is not a recoverable operation.</p>
	<a href="/account/terminate" class="error btn">Delete my account</a>
</section>

{% endblock main %}