{% extends "layout.html" %}

{% block content %}
    <section>
        <p>
            {% trans %}Sign in to explore OAuth 2.0 and OpenID Connect flows.
                Test registration, authentication, token refresh, and logout operations.{% endtrans %}
        </p>
    </section>

    <form method="POST" action="{{ url_for('oauth.authorize') }}" id="auth-params-form">
        {{ auth_params_form.hidden_tag() }}
        <details{% if session.token %} open{% endif %}>
            <summary role="button" class="outline">{% trans %}Authorization parameters{% endtrans %}</summary>

            {% if auth_params_form.scopes.choices %}
                <fieldset>
                    <legend>{{ auth_params_form.scopes.label.text }}</legend>
                    {% if auth_params_form.scopes.description %}
                        <small>{{ auth_params_form.scopes.description }}</small>
                    {% endif %}
                    {{ auth_params_form.scopes() }}
                </fieldset>
            {% endif %}

            <label>
                {{ auth_params_form.prompt.label }}
                {{ auth_params_form.prompt() }}
                {% if auth_params_form.prompt.description %}
                    <small>{{ auth_params_form.prompt.description }}</small>
                {% endif %}
            </label>

            {% if auth_params_form.ui_locales.choices|length > 1 %}
                <label>
                    {{ auth_params_form.ui_locales.label }}
                    {{ auth_params_form.ui_locales() }}
                    {% if auth_params_form.ui_locales.description %}
                        <small>{{ auth_params_form.ui_locales.description }}</small>
                    {% endif %}
                </label>
            {% endif %}
        </details>
        <button type="submit">{% trans %}Sign in{% endtrans %}</button>
    </form>

    <div class="buttons-right">
        {% if g.server_config and g.server_config.registration_access_token %}
            <div class="buttons-right">
                <form method="POST" action="{{ url_for('oauth.unregister_client') }}">
                    {{ unregister_form.hidden_tag() }}
                    {{ unregister_form.submit() }}
                </form>
            </div>
        {% endif %}
        {% if session.token and session.token.refresh_token %}
            <form method="POST" action="{{ url_for('oauth.refresh') }}">
                {{ refresh_form.hidden_tag() }}
                {{ refresh_form.submit() }}
            </form>
        {% endif %}
        {% if session.token %}
            <div role="group">
                <a href="{{ url_for('oauth.logout_local') }}" role="button" class="secondary">{% trans %}Log out{% endtrans %}</a>
                {% if g.server_config and g.server_config.specs and g.server_config.specs.oidc_rpinitiated_logout %}
                    <a href="{{ url_for('oauth.logout') }}" role="button" class="contrast">{% trans %}Server log out{% endtrans %}</a>
                {% endif %}
            </div>
        {% endif %}
    </div>
{% endblock %}
