{% extends "forms/field.html.twig" %}

{% block input %}
    <div class="form-input-wrapper twofa-wrapper">
        {% try %}
            {% set user = grav.user %}

            {% set secret = user.twofa_secret ?: grav.login.twoFactorAuth.createSecret() %}
            {% set image = grav.login.twoFactorAuth.getQrImageData(user.username, secret) %}

            <img style="border: 1px solid #ddd" data-2fa-image src="{{ image }}" />
            <div>
                <span>{{ 'PLUGIN_LOGIN.2FA_SECRET'|tu }}: </span><span class="twofa-secret-code" data-2fa-secret>{{ secret|regex_replace('/(\\w{4})/', '\\1 ') }}</span>
            </div>
            {% if admin %}
            <div class="danger twofa-wrapper">
                <button data-hint="{{ 'PLUGIN_LOGIN.2FA_REGEN_HINT'|tu }}" class="button button-small hint--bottom" data-2fa-regenerate><i class="fa fa-fw fa-refresh"></i> {{ 'PLUGIN_LOGIN.2FA_REGENERATE'|t }}</button>
            </div>
            {% endif %}
            <input type="text" class="no-form" style="display:none;" name="{{ (scope ~ field.name)|fieldName }}" data-2fa-value value="{{ secret }}" />

        {% catch %}
            <div class="notice error">
                <p>{{ e.message }}</p>
            </div>
        {% endcatch %}
    </div>
{% endblock %}
