{% extends "Froxlor/userarea.html.twig" %}

{% block content %}
	<div class="container">
		<div class="row justify-content-center">
			{% if userinfo.type_2fa == 0 %}
				{% set linkeraction = 'preadd' %}
			{% elseif userinfo['2fa_unsaved'] is defined and userinfo['2fa_unsaved'] %}
				{% set linkeraction = 'add' %}
			{% else %}
				{% set linkeraction = 'delete' %}
			{% endif %}
			<form action="{{ linker({'section':'index','action':linkeraction}) }}" class="col-12 max-w-420 d-flex flex-column" method="post" enctype="application/x-www-form-urlencoded">
				<div class="card shadow">
					<div class="card-body">
						<h5 class="card-title">{{ lng('login.2fa') }}</h5>

						<div>
							{% if userinfo.type_2fa == 0 %}
								<label for="type_2fa" class="col-form-label">{{ lng('2fa.2fa_overview_desc')|raw }}</label>
								<select class="form-select" name="type_2fa" id="type_2fa" required>
									{% for val,opt in type_select_values %}
										<option value="{{ val }}">{{ opt }}</option>
									{% endfor %}
								</select>

							{% elseif userinfo.type_2fa == 2 %}
								<label for="qrcode" class="col-form-label">{{ lng('2fa.2fa_ga_desc')|raw }}</label>
								<img src="{{ ga_qrcode }}" class="img-fluid" alt="QRCode" id="qrcode"/><br>
								<span>Code: <code>{{ userinfo.data_2fa }}</code></span>
							{% endif %}

							{% if userinfo['2fa_unsaved'] is defined and userinfo['2fa_unsaved'] %}
							<br>
							<label for="codevalidation" class="col-form-label">{{ lng('login.2facode') }}</label>
							<input type="text" name="codevalidation" id="codevalidation" class="form-control" required/>
							<input type="hidden" name="type_2fa" id="type_2fa" value="{{ userinfo.type_2fa }}"/>
							<input type="hidden" name="data_2fa" id="data_2fa" value="{{ userinfo.data_2fa }}"/>
							{% endif %}
						</div>
					</div>

					<div class="card-body d-grid gap-2">
						<input type="hidden" name="csrf_token" value="{{ csrf_token }}"/>
						<input type="hidden" name="page" value="{{ page }}"/>
						<input type="hidden" name="send" value="send"/>
						{% if userinfo.type_2fa == 0 %}
							<button class="btn btn-primary" type="submit" name="preadd">
								{{ lng('2fa.2fa_add') }}</button>
						{% elseif userinfo['2fa_unsaved'] is defined and userinfo['2fa_unsaved'] %}
							<button class="btn btn-primary" type="submit" name="add">
								{{ lng('2fa.2fa_add') }}</button>
						{% else %}
							<button class="btn btn-warning" type="submit" name="delete">
								{{ lng('2fa.2fa_delete') }}</button>
						{% endif %}
					</div>
				</div>
			</form>
		</div>
	</div>
{% endblock %}
