{% extends "users/settings_base.html" %}

{% block title %}
	{{ _("Email and Notifications - %(username)s", username=user.username) }}
{% endblock %}

{% block scriptextra %}
	<script src="/static/js/email_disable_all.js"></script>
{% endblock %}

{% block pane %}
	<h2 class="mt-0">{{ _("Email and Notifications") }}</h2>

	{% from "macros/forms.html" import render_field, render_submit_field, render_checkbox_field %}
	<form action="" method="POST" class="form" role="form">
		{{ form.hidden_tag() }}

		<h3>{{ _("Email Address") }}</h3>

		{{ render_field(form.email, tabindex=100) }}

		<p>
			{{  _("Your email is needed to recover your account if you forget your password, and to send (configurable) notifications.") }}
			{{  _("Your email will never be shared with a third-party.") }}
		</p>
		<p>
			{{ _("Note: protonmail is unsupported by ContentDB. <a href='https://forum.luanti.org/viewtopic.php?t=30709'>More info</a>.") }}
		</p>

		{% if user.email_verifications.filter_by(is_password_reset=False).count() > 0 %}
			<p>
				<i>{{ _("There is at least one verification pending.") }}</i>
			</p>
		{% endif %}

		<h3>{{ _("Notification Settings") }}</h3>

		{% if is_new %}
			<p class="alert alert-info">
				{{ _("Email notifications are currently turned off. Click 'save' to enable.") }}
			</p>
		{% endif %}

		<p>
			{{ _("Configure whether certain types of notifications are sent immediately, or as part of a daily digest.") }}
			<button type="button" id="disable-all" class="btn btn-sm btn-secondary d-none ms-5">{{ _("Disable all") }}</button>
		</p>

		<table class="table">
			<tr>
				<th>{{ _("Event") }}</th>
				<th>{{ _("Description") }}</th>
				<td>{{ _("Immediately") }}</td>
				<td>{{ _("In digest") }}</td>
			</tr>
			{% for type in types %}
				<tr>
					<td>{{ type.title }}</td>
					<td>{{ type.description }}</td>
					<td style="text-align: center;">
						{{ render_checkbox_field(form["pref_" + type.to_name()]) }}
					</td>
					<td style="text-align: center;">
						{{ render_checkbox_field(form["pref_" + type.to_name() + "_digest"]) }}
					</td>
				</tr>
			{% endfor %}
		</table>

		<p class="mt-5">
			{{ render_submit_field(form.submit, tabindex=280, class_="btn btn-lg btn-primary") }}
		</p>
	</form>
{% endblock %}
