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

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

{#      Resources:                                                                 #}

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

{# pagination \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination             #}
{#      Contains data about the current search page                                #}

{# 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      = itemLevelInfo.hasDetail ? url('listing_detail', {'friendlyUrl': data.friendlyUrl, "_format" : "html"}) : "" -%}
{% set dealURL        = data.dealFriendlyUrl ? url('deal_detail', {'friendlyUrl': data.dealFriendlyUrl, "_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 ) -%}
{% set itemBadges     = ( data.badgeId is not empty ? data.badgeId|split(" ") : null ) -%}

{% set sectionAnchor  = ( data.friendlyUrl ? data.friendlyUrl  : item.id ) ~ "listing" -%}

{% set reviewTitle = 'Review'|trans ~ ' %s'|format(data.title) %}

<section id="{{ sectionAnchor }}" class="summary-box {{ itemLevelInfo.hasBacklink and data.backlink == 'true' ? 'summary-backlink' : '' }}">
    <div class="summary-content">
        <div class="media">

            {% set flags = 0 -%}

            {% if itemLevelInfo.hasBadges and itemBadges -%} {% set flags = flags + 1 -%} {% endif -%}
            {% if itemLevelInfo.imageCount > 0 and data.thumbnail is defined and data.thumbnail is not empty -%} {% set flags = flags + 2 -%} {% endif -%}

            {% if flags -%}

                <div class="media-left media-top">

                    {% if flags b-and 2 -%}
                        {% if itemLevelInfo.hasDetail -%}
                            <a href="{{ detailURL }}">{{ Utility.image( data.thumbnail, data.title ) }}</a>
                        {% else -%}
                            {{ Utility.image( data.thumbnail, data.title ) }}
                        {% endif -%}
                    {% endif -%}

                    {% if flags b-and 1 -%}
                        <div class="summary-badges">
                            {{ Utility.badges( itemBadges, pageBadges ) }}
                        </div>
                    {% endif -%}

                </div>
            {% endif -%}

            <div class="media-body">

                <h3>
                    {% if itemLevelInfo.hasDetail -%}
                        <a href="{{ detailURL }}">{{ data.title }}</a>
                    {% else -%}
                        {{ data.title }}
                    {% endif -%}
                    {% if data.distance and data.distance < 40000 %}<span>({{ parseDistanceUnit(data.distance) }})</span>{% endif %}
                </h3>

                {% if data.categoryId is not empty %}
                <p class="categories-list">
                     {{ "in"|trans }} {{ Utility.categories( itemCategories, pageCategories, "listing" ) }}
                </p>
                {% endif %}

                {% if itemLevelInfo.hasSummaryDescription -%}
                    <p class="summary-desc">{{ data.description }}</p>
                {% endif -%}

                {{ Utility.address( null, null, data.address.street, data.address.complement, data.address.zipcode, itemLocations, pageLocations ) }}

                {% if data.claim -%}
                    {% set claimLabel = getClaimCustomText() %}
                    <p class="small">
                        <a href="{{ path("listing_claim", { "friendlyUrl" : data.friendlyUrl }) }}" class="text-info" title="{{ claimLabel ?: "Claim this listing"|trans }}">{{ claimLabel ?: "Is this your listing?"|trans }}</a>
                    </p>
                {% endif -%}

                <p>
                    {{ bookmarkLink(item, 'listing') }}

                    {% if itemLevelInfo.hasEmail and data.email is not empty -%}
                         <span class="divisor">|</span><a class="text-info sendEmailButton" data-action="{{ path('listing_sendmail',{id: item.id}) }}"><span class="fa fa-envelope-o text-success"></span>{{"Send E-mail"|trans }}</a>
                    {% endif -%}
                </p>

            </div>

            <div class="media-right text-center">

                {% if itemLevelInfo.hasReview and getSetting("review_listing_enabled") -%}
                    <div class="summary-info">
                        <span class="stars-rating"><span class="rate-{{ data.averageReview }}"></span></span>
                    </div>
                    <p>
                        <span
                            class="text-primary reviewButtonTrigger"
                            data-info="{{ encrypt( {module: 'listing', id: item.id} ) }}"
                            data-title="{{ reviewTitle }}"
                            title="{{ "Review this"|trans }}">
                            {{ 'Review this'|trans }}
                        </span>
                    </p>
                {% endif -%}

                {{ Utility.contactInfoSimple( item, data, detailURL, itemLevelInfo, "listing" ) }}

                {% if itemLevelInfo.hasClickToCall and 'on' == clicktocall_enabled -%}
                    <a class="text-info" data-toggle="modal" data-target="#modalClicktoCall" href="{{ path('listing_clickcall',{id: item.id}) }}">
                        {{ 'Click to call'|trans }}
                    </a>
                    {% include '::blocks/modals/modal-bootstrap-template.html.twig' with {id: 'modalClicktoCall'} -%}
                {% endif -%}

                <div class="social-share">

                    <div class="social-button">
                        <a target="_blank" class="popup btn-info" href="http://www.facebook.com/sharer/sharer.php?u={{ ( detailURL ?: app.request.uri ~ "#" ~ sectionAnchor)|url_encode }}">
                            <span class="fa fa-facebook"></span>
                        </a>
                    </div>

                    <div class="social-button">
                        <a target="_blank" class="popup btn-info" href="http://twitter.com/?status={{ ( detailURL ?: app.request.uri ~ "#" ~ sectionAnchor)|url_encode }}">
                            <span class="fa fa-twitter"></span>
                        </a>
                    </div>

                    <div class="social-button">
                        <a target="_blank" class="popup btn-info" href="https://plus.google.com/share?url={{ ( detailURL ?: app.request.uri ~ "#" ~ sectionAnchor)|url_encode }}">
                            <span class="fa fa-google"></span>
                        </a>
                    </div>
                </div>

            </div>
        </div>

    </div>
</section>
