<!doctype html>
<html lang="{{ locale }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="color-scheme" content="light dark">
        <title>{% block title %}{{ config.NAME }}{% endblock %} - Auth Playground</title>
        <link rel="stylesheet" href="{{ url_for('static', filename='css/pico.min.css') }}">
        <link rel="stylesheet" href="{{ url_for('static', filename='css/pico.colors.min.css') }}">
        <link rel="stylesheet" href="{{ url_for('static', filename='css/custom.css') }}">
        {% block extra_css %}{% endblock %}
    </head>

    <body>
        <header class="container">
            <div class="grid">
                <hgroup>
                    <h1><a href="{{ url_for('routes.index') }}">{{ config.NAME }}</a></h1>
                    <p>{% trans %}OAuth 2.0 Demonstration Client{% endtrans %}</p>
                </hgroup>
                <hgroup>
                    {% if g.server_config and g.server_config.issuer_url %}
                        <h1><a href="{{ g.server_config.issuer_url }}" target="_blank">{{ g.server_config.issuer_url|replace('https://', '')|replace('http://', '') }}</a></h1>
                        <p>
                            {{ g.server_config.display_name }}
                            • <a href="{{ url_for('routes.playground') }}">{% trans %}playground{% endtrans %}</a>
                            {% if session.token %}
                                • <a href="{{ url_for('routes.tokens') }}">{% trans %}tokens{% endtrans %}</a>
                            {% endif %}
                            • <a href="{{ url_for('routes.specs') }}">{% trans %}specs{% endtrans %}</a>
                            {% if not config.OAUTH_AUTH_SERVER %}
                                • <a href="{{ url_for('routes.configure_server') }}">{% trans %}switch{% endtrans %}</a>
                            {% endif %}
                        </p>
                    {% elif config.OAUTH_AUTH_SERVER %}
                        <h1><a href="{{ config.OAUTH_AUTH_SERVER }}" target="_blank">{{ config.OAUTH_AUTH_SERVER|replace('https://', '')|replace('http://', '') }}</a></h1>
                        <p>{{ g.server_config.display_name }}</p>
                    {% else %}
                        <h1>&nbsp;</h1>
                        <p>&nbsp;</p>
                    {% endif %}
                </hgroup>
            </div>
        </header>

        <main class="container">
            {% with messages = get_flashed_messages(with_categories=true) %}
                {% if messages %}
                    {% for category, message in messages %}
                        <article role="alert" data-type="{{ category }}">
                            {{ message }}
                        </article>
                    {% endfor %}
                {% endif %}
            {% endwith %}

            {% block content %}{% endblock %}
        </main>

        <footer class="container">
            <p>
                <small>Auth Playground <a href="{{ repository_url }}" target="_blank" rel="noopener noreferrer">v{{ app_version }}</a></small>
                •
                <small><a href="{{ url_for('routes.tos') }}">{% trans %}Terms of Service{% endtrans %}</a></small>
                •
                <small><a href="{{ url_for('routes.policy') }}">{% trans %}Privacy Policy{% endtrans %}</a></small>
                •
                <small>{% trans %}Powered by{% endtrans %} <a href="https://authlib.org" target="_blank">Authlib</a></small>
            </p>
            <p>
                <small>
                    {% for lang in available_languages %}
                        {% if not loop.first %} • {% endif %}
                        {% if lang.language == locale.language %}
                            <strong>{{ lang.get_language_name(lang.language).title() }}</strong>
                        {% else %}
                            {# Build URL for current page with different language #}
                            {% set view_args = request.view_args.copy() if request.view_args else {} %}
                            {% set _ = view_args.pop('lang_code', None) %}
                            <a href="{{ url_for(request.endpoint, lang_code=lang.language, **view_args) }}">{{ lang.get_language_name(lang.language).title() }}</a>
                        {% endif %}
                    {% endfor %}
                </small>
            </p>
        </footer>

        {% block scripts %}{% endblock %}
    </body>
</html>
