{% set route = app.request.attributes.get('_route') %}
{% set route_parameters = app.request.attributes.get('_route_params')|merge(app.request.query.all) %}
{% set criteria = app.request.query.get('criteria', {}) %}
{% set default_path = path(route, route_parameters|merge({'sorting': null, 'criteria': criteria})) %}
{% set from_a_to_z_path = path(route, route_parameters|merge({'sorting': {'name': 'asc'}, 'criteria': criteria})) %}
{% set from_z_to_a_path = path(route, route_parameters|merge({'sorting': {'name': 'desc'}, 'criteria': criteria})) %}
{% set oldest_first_path = path(route, route_parameters|merge({'sorting': {'createdAt': 'asc'}, 'criteria': criteria})) %}
{% set newest_first_path = path(route, route_parameters|merge({'sorting': {'createdAt': 'desc'}, 'criteria': criteria})) %}
{% set cheapest_first_path = path(route, route_parameters|merge({'sorting': {'price': 'asc'}, 'criteria': criteria})) %}
{% set most_expensive_first_path = path(route, route_parameters|merge({'sorting': {'price': 'desc'}, 'criteria': criteria})) %}
{% set current_sorting_label = 'sylius.ui.by_position'|trans %}
{% if app.request.query.get('sorting') is empty %}
{% set current_sorting_label = 'sylius.ui.by_position'|trans %}
{% elseif app.request.query.get('sorting').name is defined and app.request.query.get('sorting').name == 'asc'%}
{% set current_sorting_label = 'sylius.ui.from_a_to_z'|trans %}
{% elseif app.request.query.get('sorting').name is defined and app.request.query.get('sorting').name == 'desc'%}
{% set current_sorting_label = 'sylius.ui.from_z_to_a'|trans %}
{% elseif app.request.query.get('sorting').createdAt is defined and app.request.query.get('sorting').createdAt == 'desc'%}
{% set current_sorting_label = 'sylius.ui.newest_first'|trans %}
{% elseif app.request.query.get('sorting').createdAt is defined and app.request.query.get('sorting').createdAt == 'asc'%}
{% set current_sorting_label = 'sylius.ui.oldest_first'|trans %}
{% elseif app.request.query.get('sorting').price is defined and app.request.query.get('sorting').price == 'asc'%}
{% set current_sorting_label = 'sylius.ui.cheapest_first'|trans %}
{% elseif app.request.query.get('sorting').price is defined and app.request.query.get('sorting').price == 'desc' %}
{% set current_sorting_label = 'sylius.ui.most_expensive_first'|trans %}
{% endif %}
<div class="ui right floated small header sorting js-sort-form-ajax">
<div class="content">
{{ 'sylius.ui.sort'|trans }}:
<div class=" sorting-ctn">
<div class="text">{{ current_sorting_label }}</div>
<i class="dropdown icon"></i>
<div class="menu">
<a class="item" rel="nofollow" href="{{ default_path }}" data-text="{{ 'sylius.ui.by_position'|trans|lower }}">{{ 'sylius.ui.by_position'|trans }}</a>
<a class="item" rel="nofollow" href="{{ from_a_to_z_path }}" data-text="{{ 'sylius.ui.from_a_to_z'|trans|lower }}" data-sort-by="name" data-sort-value="asc">{{ 'sylius.ui.from_a_to_z'|trans }}</a>
<a class="item" rel="nofollow" href="{{ from_z_to_a_path }}" data-text="{{ 'sylius.ui.from_z_to_a'|trans|lower }}" data-sort-by="name" data-sort-value="desc">{{ 'sylius.ui.from_z_to_a'|trans }}</a>
<a class="item" rel="nofollow" href="{{ newest_first_path }}" data-text="{{ 'sylius.ui.newest_first'|trans|lower }}" data-sort-by="created_at" data-sort-value="desc">{{ 'sylius.ui.newest_first'|trans }}</a>
<a class="item" rel="nofollow" href="{{ oldest_first_path }}" data-text="{{ 'sylius.ui.oldest_first'|trans|lower }}" data-sort-by="created_at" data-sort-value="asc">{{ 'sylius.ui.oldest_first'|trans }}</a>
<a class="item" rel="nofollow" href="{{ cheapest_first_path }}" data-text="{{ 'sylius.ui.cheapest_first'|trans|lower }}" data-sort-by="price" data-sort-value="asc">{{ 'sylius.ui.cheapest_first'|trans }}</a>
<a class="item" rel="nofollow" href="{{ most_expensive_first_path }}" data-text="{{ 'sylius.ui.most_expensive_first'|trans|lower }}" data-sort-by="price" data-sort-value="desc">{{ 'sylius.ui.most_expensive_first'|trans }}</a>
</div>
</div>
</div>
</div>