{# It extends from base.html.twig because I needed the css file to display it better #}
{% extends "::base.html.twig" -%}

{% block SEO %}{% endblock %}
{% block nav -%}{% endblock %}
{% block subheader -%}{% endblock %}
{% block bottombanners -%}{% endblock %}
{% block footer -%}{% endblock %}
{% block scripts -%}{% endblock %}
{% block topbanner -%}{% endblock -%}

{% set addresses  = [locations.country.name, locations.region.name, locations.state.name, locations.city.name, locations.neighborhood.name] -%}

{# @var user \ArcaSolutions\CoreBundle\Entity\Contact #}

{# The content of this view will be loaded inside of bootstrap's modal structure -#}
{# p.s: This content will always be written inside the .modal-content div -#}

{# Don't remove this div, jquery wont work without it -#}
{% block body -%}
    <div>
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
            <h4 class="modal-title">{{ 'Redeem Deal'|trans }} </h4>
        </div>
        <div class="modal-body">
            <br>

            <div class="alert-info well-lg text-center">
                <h3>
                    {{ redeem.redeemCode }}
                </h3>
            </div>
            <br>

            <div class="row">
                <div class="col-sm-10 col-sm-offset-1">
                    <h4 class="text-center">{{ deal.name }}</h4>

                    <p>
                        <b>{{ 'Name'|trans }}</b>: {{ user.firstName }} {{ user.lastName }} <br>
                        <b>{{ 'Redemeed at'|trans }}</b>: {{ redeem.datetime|localized_date('LLLL dd, yyyy - kk:mm') }}
                        <br>
                        <b>{{ 'Valid until'|trans }}</b>: {{ date(deal.startDate)|localized_date('LLLL dd, yyyy') }}
                        <br>
                        <b>{{ 'Original value'|trans }}</b>: {{ deal.realValue|localized_currency }}
                        <br>
                        <b>{{ 'This deal value'|trans }}</b>: {{ deal.dealValue|localized_currency }}
                        <br>
                        <b>{{ 'Listing'|trans }}</b>: {{ deal.listing.title }} <br>
                        <b>{{ 'Phone'|trans }}</b>: {{ deal.listing.phone }} <br>
                        <b>{{ 'E-mail'|trans }}</b>: {{ deal.listing.email }} <br>
                        <b>{{ 'Address'|trans }}</b>: {{ deal.listing.address }}
                        {{ deal.listing.address2 ? ',' ~ deal.listing.address2 : '' }}
                        , {{ deal.listing.zipCode }}
                        {# lists all address saved excluding locations not linked. Addresses is in the file's beginning -#}
                        {% for address in addresses if address -%}
                            {% if not index.last -%},{% endif -%}
                            {{ address }}
                        {% endfor -%}
                    </p>
                    <br class="hidden-print">

                    <p class="text-center hidden-print">
                        <button type="submit" class="btn btn-success"
                            onclick="javascript:window.open('{{ path('deal_redeem', {id: deal.id}) }}');">{{ "Print Deal"|trans }} </button>
                    </p>
                    <p class="text-center hidden-print">
                        <a class="btn btn-facebook btn-sm" target="_blank"
                           href="https://www.facebook.com/sharer/sharer.php?u={{ app.request.schemeAndHttpHost~path('deal_detail', {friendlyUrl: deal.friendlyUrl, _format: 'html'}, false) }}">{{ 'Share on Facebook'|trans }}</a>
                    </p>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <div class="row">
                <div class="col-sm-10 col-sm-offset-1">
                    <p class="small text-muted text-left">{{ deal.conditions }}</p>
                    <br>
                </div>
            </div>
        </div>
    </div>

    {% if not app.request.isXmlHttpRequest() %}
        {# it is not a ajax request(modal) #}
        <script>
            window.print();
        </script>
    {% endif %}
{% endblock -%}
