{#

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.

#}

<!--
This template can be customized to match your needs. You should only extends the template and used the different blocks to customize the view:
    - sonata_mosaic_default_view
    - sonata_mosaic_hover_view
    - sonata_mosaic_description
-->

<tr>
    {# NEXT_MAJOR: Remove the NAME_ACTIONS check in version 5 and recommend using the option `ajax_hidden` instead. #}
    <td colspan="{{
        app.request.isXmlHttpRequest
            ? admin.list.getElements()|filter(element => element.getOption('ajax_hidden') != true)|length
                - admin.list.has(constant('Sonata\\AdminBundle\\Datagrid\\ListMapper::NAME_ACTIONS'))
                - admin.list.has(constant('Sonata\\AdminBundle\\Datagrid\\ListMapper::NAME_BATCH'))
            : admin.list.getElements()|length
    }}">
        <div class="row">
            {% for object in admin.datagrid.results %}
                {% set meta = admin.getObjectMetadata(object) %}
                {% set mosaic_content %}
                    <div class="mosaic-box-outter">
                        <div class="mosaic-inner-box">
                            {#
                                This box will be display when the mouse is not on the box
                            #}

                            <div class="mosaic-inner-box-default">
                                {% block sonata_mosaic_background %}
                                    {% set metaImage = meta.isImageAvailable is defined and not meta.isImageAvailable ? sonata_config.getOption('mosaic_background') : meta.image %}
                                    {% if not (metaImage starts with 'data:') %}
                                        {% set metaImage = asset(metaImage) %}
                                    {% endif %}
                                    <img src="{{ metaImage }}" alt="{{ meta.title }}" />
                                {% endblock %}
                                {% block sonata_mosaic_default_view %}
                                    <span class="mosaic-box-label label label-primary pull-right">#{{ admin.id(object) }}</span>
                                {% endblock %}
                            </div>

                            {#
                                This box will be display when the mouse is on the box
                                You can add more description
                            #}
                            <div class="mosaic-inner-box-hover">
                                {% block sonata_mosaic_hover_view %}
                                    <span class="mosaic-box-label label label-primary pull-right">#{{ admin.id(object) }}</span>
                                    {{ meta.description }}
                                {% endblock %}
                            </div>
                        </div>

                        <div class="mosaic-inner-text">
                            {% if (admin.hasRoute('batch') and batchactions|length > 0) or (admin.hasRoute('export') and admin.hasAccess('export') and export_formats|length) %}
                                <input type="checkbox" name="idx[]" value="{{ admin.id(object) }}">
                            {% else %}
                                &nbsp;
                            {% endif %}

                            {% block sonata_mosaic_description %}
                                {{ meta.title|u.truncate(40) }}
                            {% endblock %}
                        </div>
                    </div>
                {% endset %}
                <div class="col-xs-6 col-sm-3 mosaic-box sonata-ba-list-field-batch sonata-ba-list-field"
                     objectId="{{ admin.id(object) }}">
                    {% if admin.hasAccess('edit', object) and admin.hasRoute('edit') %}
                        <a class="mosaic-inner-link"
                           href="{{ admin.generateObjectUrl('edit', object) }}">
                            {{ mosaic_content }}
                        </a>
                    {% elseif admin.hasAccess('show', object) and admin.hasRoute('show') %}
                        <a class="mosaic-inner-link"
                           href="{{ admin.generateObjectUrl('show', object) }}">
                            {{ mosaic_content }}
                        </a>
                    {% else %}
                        {{ mosaic_content }}
                    {% endif %}
                </div>

                {% if loop.index % 4 == 0 %}
                    <div class="clearfix hidden-xs"></div>
                {% endif %}
                {% if loop.index % 2 == 0 %}
                    <div class="clearfix visible-xs"></div>
                {% endif %}
            {% endfor %}
        </div>
    </td>
</tr>
