{#

This file is part of the Sonata package.

(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{%- apply spaceless %}
    {% set choices = choices|default([]) %}
    {% if multiple|default(false) and value is iterable %}

        {% set result = '' %}
        {% for val in value %}
            {% if result is not empty %}
                {% set result = result ~ delimiter|default(', ') %}
            {% endif %}

            {% if choices[val] is defined %}
                {% set choice = choices[val] %}
            {% else %}
                {% set choice = val %}
            {% endif %}
            {% if translation_domain|default(null) is null %}
                {% set result = result ~ choice %}
            {% else %}
                {% set result = result ~ choice|trans({}, translation_domain) %}
            {% endif %}
        {% endfor %}

        {% set value = result %}

    {% elseif value in choices|keys %}
        {% if translation_domain|default(null) is null %}
            {% set value = choices[value] %}
        {% else %}
            {% set value = choices[value]|trans({}, translation_domain) %}
        {% endif %}
    {% endif %}

    {% if safe|default(false) %}
        {{ value|raw }}
    {% else %}
        {{ value }}
    {% endif %}
{% endapply -%}
