{#
    Template to render an address

    OPTIONS
    * render            string ['list'|'bloc'|'inline']
    * with_valid_from   bool    start date
    * with_valid_to     bool    end date
    * with_picto        bool    add a forkawesome pictogram
    * with_delimiter    bool    add a delimiter between fragments
    * has_no_address    bool
    * multiline         bool    multiline display
    * extended_infos    bool    add extra informations (step, floor, etc.) DEPRECATED
    * details_button    bool    add an address details button

#}

{% macro raw(lines) %}
    {% for l in lines %}
        <p>{{ l }}</p>
    {% endfor %}
{% endmacro %}

{% macro inline(address, options, streetLine, lines) %}
    {% if options['has_no_address'] == true and address.isNoAddress == true %}
        {% if address.postCode is not empty %}
            <p class="postcode">
                <span class="code">{{ address.postCode.code }}</span>
                <span class="name">{{ address.postCode.name }}</span>
                <span class="name">{{ address.distribution }}</span>
            </p>
            <p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
        {% endif %}
        {% if address.extra is not empty %}
        <span>
            {{ address.extra }}
        </span>
        {% endif %}
        <span class="noaddress">
            {{ 'address.consider homeless'|trans }}
        </span>
    {% else %}
        <span class="address{% if options['multiline'] %} multiline{% endif %}{% if options['with_delimiter'] %} delimiter{% endif %}">
            {{ _self.raw(lines) }}
        </span>
    {% endif %}
    {{ _self.validity(address, options) }}
{% endmacro %}

{% macro validity(address, options) %}
    {%- if options['with_valid_from'] == true -%}
        <span class="address-valid date-since">
            {{ 'Since %date%'|trans( { '%date%' : address.validFrom|format_date('long') } ) }}
        </span>
    {%- endif -%}
    {%- if options['with_valid_to'] == true -%}
        <span class="address-valid date-until">
            {{ 'Until %date%'|trans( { '%date%' : address.validTo|format_date('long') } ) }}
        </span>
    {%- endif -%}
{% endmacro %}


{#
    this enclose the rendering inside a "li", which ease the placement operation when the address
    must be shown in such list
#}
{%- if render == 'list' -%}
    <li class="chill-entity entity-address {% if address.confidential %} confidential {% endif %}">
        {% if options['with_picto'] %}
            <i class="fa fa-li fa-map-marker"></i>
        {% endif %}
        {{ _self.inline(address, options, streetLine, lines) }}
        <span data-address-details="1" data-address-id="{{ address.id|escape('html_attr') }}" data-address-ref-status="{{ address.refStatus|escape('html_attr') }}" ></span>
    </li>
{%- endif -%}

{%- if render == 'inline' -%}
    <span class="chill-entity entity-address {% if address.confidential %} confidential {% endif %}">
        {% if options['with_picto'] %}
            <i class="fa fa-fw fa-map-marker"></i>
        {% endif %}
        {{ _self.inline(address, options, streetLine, lines) }}
        {% if options['details_button'] is defined and options['details_button'] == true  %}
            <span data-address-details="1"
                data-address-id="{{ address.id|escape('html_attr') }}"
                data-address-ref-status="{{ address.refStatus|escape('html_attr') }}">
            </span>
        {% endif %}
    </span>
{%- endif -%}

{%- if render == 'bloc' -%}
    <div class="chill-entity entity-address {% if address.confidential %} confidential {% endif %}">
        {% if options['has_no_address'] == true and address.isNoAddress == true %}
            {% if address.postCode is not empty %}
            <div class="address{% if options['multiline'] %} multiline{% endif %}{% if options['with_delimiter'] %} delimiter{% endif %}">
                <p class="postcode">
                    <span class="code">{{ address.postCode.code }}</span>
                    <span class="name">{{ address.postCode.name }}</span>
                    <span class="name">{{ address.distribution }}</span>
                </p>
                <p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
            </div>
            {% endif %}
            {% if address.extra is not empty %}
            <div>
                {{ address.extra }}
            </div>
            {% endif %}
            <div class="noaddress">
                {{ 'address.consider homeless'|trans }}
            </div>
            <p><span data-address-details="1" data-address-id="{{ address.id|escape('html_attr') }}" data-address-ref-status="{{ address.refStatus|escape('html_attr') }}" ></span></p>

        {% else %}
            <div class="address{% if options['multiline'] %} multiline{% endif %}{% if options['with_delimiter'] %} delimiter{% endif %}">
                {% if options['with_picto'] %}
                    <i class="fa fa-fw fa-map-marker"></i>
                {% endif %}
                {{ _self.raw(lines) }}
                {% if options['details_button'] is defined and options['details_button'] == true  %}<p class="mt-3">
                    <span data-address-details="1"
                        data-address-id="{{ address.id|escape('html_attr') }}"
                        data-address-ref-status="{{ address.refStatus|escape('html_attr') }}">
                    </span></p>
                {% endif %}
            </div>
        {% endif %}
        {{ _self.validity(address, options) }}
    </div>
{%- endif -%}

