{% block layout_header_actions_language_widget%}
    {% if position is empty %}
        {% set position = 'top-bar' %}
    {% endif %}

    {% if page.header.languages.count > 1 %}
        <div class="top-bar-nav-item top-bar-language">
            {% block layout_header_actions_language_widget_form %}
                <form method="post"
                      action="{{ path('frontend.checkout.switch-language') }}"
                      class="language-form"
                      data-form-auto-submit="true">

                    {% block layout_header_actions_language_widget_content %}
                        {% set isoCode = page.header.activeLanguage.translationCode.code|lower|split('-') %}
                        {% set language = isoCode[0] %}
                        {% set country = isoCode[1] %}

                        <div class="languages-menu dropdown">
                            <button class="btn dropdown-toggle top-bar-nav-btn"
                                    type="button"
                                    id="languagesDropdown-{{ position }}"
                                    data-bs-toggle="dropdown"
                                    aria-haspopup="true"
                                    aria-expanded="false">
                                <div class="top-bar-list-icon language-flag country-{{ country }} language-{{ language }}"></div>
                                <span class="top-bar-nav-text">{{ page.header.activeLanguage.name }}</span>
                            </button>
                            {% block layout_header_actions_languages_widget_form_items %}
                                <div class="top-bar-list dropdown-menu dropdown-menu-end"
                                    aria-labelledby="languagesDropdown-{{ position }}">
                                    {% for language in page.header.languages %}
                                        <div class="top-bar-list-item dropdown-item{% if language.id is same as(page.header.activeLanguage.id) %} item-checked{% endif %}"
                                             title="{{ language.translated.name }}">

                                            {% block layout_header_actions_languages_widget_form_items_flag %}
                                                {% set isoCode = language.translationCode.code|lower|split('-') %}
                                                {% set flagLanguage = isoCode[0] %}
                                                {% set flagCountry = isoCode[1] %}

                                                <label class="top-bar-list-label"
                                                       for="{{ position }}-{{ language.id }}">
                                                    <input id="{{ position }}-{{ language.id }}"
                                                           class="top-bar-list-radio"
                                                           value="{{ language.id }}"
                                                           name="languageId"
                                                           type="radio"
                                                        {% if language.id is same as(page.header.activeLanguage.id) %} checked{% endif %}>
                                                    <div class="top-bar-list-icon language-flag country-{{ flagCountry }} language-{{ flagLanguage }}"></div>
                                                    {{ language.name }}
                                                </label>
                                            {% endblock %}
                                        </div>
                                    {% endfor %}
                                </div>
                            {% endblock %}
                        </div>

                        <input name="redirectTo" type="hidden" value="{{ app.request.get('_route') }}">

                        {% for key, value in app.request.attributes.get('_route_params') %}
                            <input name="redirectParameters[{{ key }}]" type="hidden" value="{{ value }}">
                        {% endfor %}
                    {% endblock %}
                </form>
            {% endblock %}
        </div>
    {% endif %}
{% endblock %}
