{% load converter_tags %}

{% if instance %}

    {% converter_get_object_image_data obj=instance width=size_preview_width height=size_preview_height as object_image_data %}
    {% if 'app_image_error_image' in object_image_data %}
        {% if object_image_data.app_image_error_image.template_name %}
            {% include object_image_data.app_image_error_image.template_name %}
        {% else %}
            {% include "documents/invalid_document.html" %}
        {% endif %}
    {% else %}
        <a
            class="fancybox"
            {% if disable_title_link %}
                data-caption="{{ instance }}"
            {% else %}
                data-caption="<a class='a-caption' href='{{ instance.get_absolute_url }}'>{{ instance }} <i class='fa fa-external-link-alt'></i></a>"
            {% endif %}
            href="{{ object_image_data.url }}"
            data-type="image"
            {% if gallery_name %}data-fancybox="{{ gallery_name }}"{% endif %}
        >
            {% with 'lazy-load thin_border-thumbnail' as image_classes %}
            {% with '200px' as image_max_height %}
            {% with size_thumbnail_width as image_width %}
            {% with size_thumbnail_height as image_height %}
                {% include 'documents/forms/widgets/page_image.html' %}
            {% endwith %}
            {% endwith %}
            {% endwith %}
            {% endwith %}
        </a>
    {% endif %}
{% endif %}
