{% if context == 'select' %}
<form autocomplete="off" class="d-inline">
<select class=" sort_estate custom-select {{ class }}">
{# <option value="si_mandatexclusif-DESC" {% if sort_by == 'si_mandatexclusif-DESC' %}selected="selected"{% endif %}>Exclusivité</option> #}
<option value="numeromandat-DESC" {% if sort_by == 'numeromandat-DESC' %}selected="selected"{% endif %}>+ Récent</option>
<option value="numeromandat-ASC" {% if sort_by == 'numeromandat-ASC' %}selected="selected"{% endif %}>- Récent</option>
<option value="prix-DESC" {% if sort_by == 'prix-DESC' %}selected="selected"{% endif %} >Prix ↓</option>
<option value="prix-ASC" {% if sort_by == 'prix-ASC' %}selected="selected"{% endif %}>Prix ↑</option>
</select>
</form>
{% elseif context == 'desktop' %}
{# Dropdown custom pour tri #}
<div class="sort_estate_dropdown custom-dropdown d-inline">
<button class="btn" type="button" id="dropdownSort" data-bs-toggle="dropdown">
{% set labels = {
'numeromandat-DESC': '+ Récent',
'numeromandat-ASC': '- Récent',
'prix-DESC': 'Prix ↓',
'prix-ASC': 'Prix ↑',
} %}
<span id="sortLabel">{{ labels[sort_by]|default('Trier') }}</span>
<span class="icon"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownSort">
{% for value, label in labels %}
<li>
<a href="#" class="dropdown-item {% if sort_by == value %}active text-white bg-primary{% endif %}" data-value="{{ value }}">
{{ label }}
</a>
</li>
{% endfor %}
</ul>
</div>
{# <script type="text/javascript">
$(document).ready(function() {
$('.dropdown-item').click(function(e) {
e.preventDefault();
var value = $(this).data('value');
var label = $(this).text();
// Mettre à jour le champ caché
$('#sort_by').val(value);
// Mettre à jour le texte du bouton (sans toucher le SVG)
$('#sortLabel').text(label);
// Mettre à jour l'option active
$('.dropdown-item').removeClass('active text-white bg-primary');
$(this).addClass('active text-white bg-primary');
});
});
</script> #}
{% endif %}