{% if not app.request.cookies.has(constant('App\\Controller\\Frontend\\CountryController::COOKIE_NAME')) and current_country_doesnt_match_ip_address() %}
<div class="header-change-country clearfix">
{% set visitor_country = get_visitor_country() %}
{% set visitor_country_default_locale = get_country_default_locale(visitor_country) %}
{% set visitor_country_proposed_locales = get_country_proposed_locales(visitor_country) %}
{% set domain = get_visitor_country_domain() %}
<div>
{% if visitor_country_proposed_locales %}
{% for locale in visitor_country_proposed_locales %}
{% set locale_with_country = locale|lower ~ '_' ~ visitor_country|upper %}
{% if not loop.first %}/{% endif %}
{{ 'frontend.header.switch.country'|trans({'%domain%': domain}, 'messages', locale_with_country) }}
{% endfor %}
{% else %}
{{ 'frontend.header.switch.country'|trans({'%domain%': domain}, 'messages', visitor_country_default_locale) }}
{% endif %}
</div>
<div>
{# “|default({})” will avoid an error when calling merge on an empty array #}
{% set route_params = app.request.attributes.get('_route_params')|default({}) %}
{# merge the query string params to keep them when switching the locale #}
{% set route_params = route_params|merge(app.request.query.all) %}
{# we must overwrite the locale from the current page #}
{% set route_params = route_params|merge({'_locale': visitor_country_default_locale}) %}
{% set switch_country_url= (
app.request.scheme ~
'://' ~
domain ~
get_route_for_country(visitor_country, app.request.get('_route') ? app.request.get('_route') : 'homepage', route_params)
) %}
<a href="{{ switch_country_url }}">✔️
{% if visitor_country_proposed_locales %}
{% for locale in visitor_country_proposed_locales %}
{% if not loop.first %}/{% endif %}
{{ 'frontend.header.switch.country.yes'|trans({'%domain%': domain}, 'messages', locale)|capitalize }}
{% endfor %}
{% else %}
{{ 'frontend.header.switch.country.yes'|trans({'%domain%': domain}, 'messages', visitor_country_default_locale)|capitalize }}
{% endif %}</a>
</div>
<div>
<a href="{{ path('frontend_dont_change_country') }}" id="dont-change-country">✘ {% if visitor_country_proposed_locales %}
{% for locale in visitor_country_proposed_locales %}
{% if not loop.first %}/{% endif %}
{{ 'frontend.header.switch.country.no'|trans({'%domain%': app.request.host}, 'messages', locale)|capitalize }}
{% endfor %}
{% else %}
{{ 'frontend.header.switch.country.no'|trans({'%domain%': app.request.host}, 'messages', visitor_country_default_locale)|capitalize }}
{% endif %}</a>
</div>
</div>
{% endif %}