{% import "::blocks/utility/summary.html.twig" as Utility -%}

{#      Description:                                                               -#}
{# This page renders the Deal summary block which appears during searches          -#}

{#      Resources:                                                                 -#}

{# item \Elastica\Result                                                           -#}
{#      The elastica result object                                                 -#}

{# levelFeatures \ArcaSolutions\ListingBundle\Entity\Internal\ListingLevelFeatures -#}
{#      Contains information about every level of a certain module                 -#}

{% set data           = extractDataFromResult(item) -%}

{# itemLevelInfo \ArcaSolutions\ListingBundle\Entity\Internal\ListingLevelFeatures -#}
{% set itemLevelInfo  = levelFeatures['listing'][data.level] -%}

{% set detailURL      = url('deal_detail', {'friendlyUrl': data.friendlyUrl, "_format" : "html"}) -%}
{% set listingURL     = data.listing.friendlyUrl ? url('listing_detail', {'friendlyUrl': data.listing.friendlyUrl, "_format" : "html"}) : null -%}

{% set itemCategories = ( data.categoryId is not empty ? data.categoryId|split(" ") : null ) -%}
{% set itemLocations  = ( data.locationId is not empty ? data.locationId|split(" ")|sort|reverse : null ) -%}

<div class="summary-box summary-map">
    <div class="summary-content">
    <h3>
        <a href="{{ detailURL }}" >{{ data.title }}</a>

        {% if data.distance and data.distance < 40000 %}<span>({{ parseDistanceUnit(data.distance) }})</span>{% endif %}
    </h3>
    <div class="row">
        {% if data.thumbnail is not empty %}
        <div class="col-md-8">
        {% else %}
        <div class="col-sm-12">
        {% endif %}

                {% set listinglink = itemLevelInfo.hasDetail ? '<a href="'~listingURL|escape~'">'~data.listing.title|escape~'</a>' : data.listing.title|escape -%}

                {% if listinglink is not empty -%}
                    <p>
                        {{ "Offered by"|trans }} <strong>{{ listinglink|raw }}</strong>
                    </p>
                {% endif -%}

                <hr>
                <p class="summary-desc">{{ (data.description[:100]|striptags) }}... <a href="{{ detailURL }}">{{ "(Read More)"|trans }}</a></p>

                <div class="row">
                    <div class="col-sm-12">
                        <div class="media-right text-center">
                            <div class="deal-details">
                                <em>
                                    {% set priceFlags = 0 %}
                                    {% if data.value.real > 0 %}{% set priceFlags = priceFlags + 1 %}{% endif %}
                                    {% if data.value.deal > 0 %}{% set priceFlags = priceFlags + 2 %}{% endif %}

                                    {% if priceFlags == 0 %}
                                        <span class="text-highlight large">{{ "Free"|trans }}</span>
                                    {% else %}
                                        {% if priceFlags b-and 1 %}<span class="text-striketrough">${{ data.value.real }}</span><br>{% endif %}
                                        {% if priceFlags b-and 2 %}
                                            <span class="text-highlight large">${{ data.value.deal }}</span>
                                        {% else %}
                                            <span class="text-highlight large">{{ "Free"|trans }}</span>
                                        {% endif %}
                                    {% endif %}
                                </em>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            {% if data.thumbnail is not empty %}
            <div class="col-md-4 hidden-sm">
                {{ Utility.image( data.thumbnail, data.title ) }}
            </div>
            {% endif %}
        </div>
    </div>
</div>
