{% macro html_titleh1(item, url = true, label = 'title') %}
{% if item[label] %}
    <h1 class="{{ label }}">
        {% if url %}<a href="{{ item.url|raw }}" title="{{ item[label]|striptags|raw }}">{% endif %}{{ item[label]|raw }}{% if url %}</a>{% endif %}
    </h1>
{% endif %}
{% endmacro %}

{% macro html_titleh2(item, url = true, label = 'title', title = 'label') %}
{% if item[label] %}
    <h2 class="{{ label }}">{% if url %}<a href="{{ item.url }}" title="{{ item[title]|striptags|raw }}">{% endif %}{{ item[label]|raw }}{% if url %}</a>{% endif %}</h2>
{% endif %}
{% endmacro %}

{% macro html_figure(item, src ='thumb', imgClass = 'img-responsive', url = true, icon = 'fa-eye', figureClass = null) %}
{% if item[src] %}
{% if item.legend %}
{% set legend = item.legend|striptags|raw %}
{% else %}
{% set legend = item.label|striptags|raw %}
{% endif %}
<figure class="image-hover">
    {% if url %}<a href="{{ item.url }}" title="{{ legend }}" target="{{ item.target|default('_parent') }}">{% endif %}
    <span class="image-hover-icon"><i class="fa {{ icon }}" aria-hidden="true"></i></span>
    <picture>
        <source srcset="{{ item[src].webp.src }}" type="{{ item[src].webp.mimetype }}">
        <source srcset="{{ item[src].image.src }}" type="{{ item[src].image.mimetype }}">

        <img class="{{ imgClass }}" width="{{ item[src].image.width }}" height="{{ item[src].image.height }}" alt="{{ legend }}">
    </picture>
    {% if url %}</a>{% endif %}
</figure>
{% endif %}
{% endmacro %}

{% macro html_figureLightbox(item, imgClass = 'img-thumbnail', thumb = 'thumb', original = 'original', icon = 'fa-search-plus', figureClass = 'pull-right img-cover') %}
{% if item[thumb] %}
{% if item.legend %}
{% set legend = item.legend|striptags|raw %}
{% else %}
{% set legend = item.label|striptags|raw %}
{% endif %}
<figure{% if figureClass %} class="{{ figureClass }}"{% endif %}>
    <a href="{{ item[original].image.src }}" title="{{ item.legend }}" class="lightbox image-hover" data-plugin-options='{"type":"image"}'>
        <span class="image-hover-icon"><i class="fa {{ icon }}" aria-hidden="true"></i></span>
        <picture>
            <source srcset="{{ item[thumb].webp.src }}" type="{{ item[thumb].webp.mimetype }}">
            <source srcset="{{ item[thumb].image.src }}" type="{{ item[thumb].image.mimetype }}">
            <img class="{{ imgClass }}" width="{{ item[thumb].image.width }}" height="{{ item[thumb].image.height }}" alt="{{ item.legend }}">
        </picture>
    </a>
</figure>
{% endif %}
{% endmacro %}

{% macro html_figureSimple(item, src ='thumb', imgClass = 'img-responsive', url = true, figureClass = 'default') %}
{% if item[src] %}
{% if item.legend %}
{% set legend = item.legend|striptags|raw %}
{% else %}
{% set legend = item.label|striptags|raw %}
{% endif %}
<figure class="{{ figureClass }}">
    {% if url %}<a href="{{ item.url }}" title="{{ legend }}" target="{{ item.target|default('_parent') }}">{% endif %}
        <picture class="picture_{{ figureClass }}">
            <source srcset="{{ item[src].webp.src }}" type="{{ item[src].webp.mimetype }}">
            <source srcset="{{ item[src].image.src }}" type="{{ item[src].image.mimetype }}">
            <img class="{{ imgClass }}" width="{{ item[src].image.width }}" height="{{ item[src].image.height }}" alt="{{ legend }}">
        </picture>
    {% if url %}</a>{% endif %}
</figure>
{% endif %}
{% endmacro %}

{% macro html_video(item) %}
{% if item.video.src %}
<div class="embed-responsive embed-responsive-16by9">
    <iframe class="embed-responsive-item" src="{{ item.video.src.embed }}"></iframe>
</div>
{% endif %}
{% endmacro %}

{% macro html_videoThumbnail(item, imgClass = 'img-thumbnail', url = true) %}
{% if item.video.thumb.url %}
<figure>
  {% if url %}<a href="{{ item.url }}" title="{% if item.legend %}{{ item.legend|striptags|raw }}{% else %}{{ item.label|striptags|raw }}{% endif %}"{% if item.target %} target="{{ item.target }}"{% endif %}>{% endif %}
    <img src="{{ item.video.thumb.url }}" class="{{ imgClass }}" alt="{% if item.legend %}{{ item.legend|striptags|raw }}{% else %}{{ item.label|striptags|raw }}{% endif %}">
  {% if url %}</a>{% endif %}
</figure>
{% endif %}
{% endmacro %}

{% macro html_listOptions(item, og, url = true) %}
{% import _self as macroElements %}
{% if item.dependence or item.dateinit or item.date or item.code %}
<ul class="list-inline list-component">
    {% if og == 'inserir' %}
    <li>
        <div class="fb-like" data-href="{{ og.url|raw }}" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div>
    </li>
    {% endif %}

    {% if item.code %}
    <li>{{ macroElements.html_code(item) }}</li>
    {% endif %}

    {% if item.date %}
    <li>{{ macroElements.html_date(item, 'date', url) }}{% if item.hour|raw %} às {{ item.hour|raw }}{% endif %}</li>
    {% endif %}
    {% if item.dateinit %}
    <li>{{ macroElements.html_date(item, 'dateinit', url) }}{% if item.hour|raw %} às {{ item.hour|raw }}{% endif %}</li>
    {% endif %}
    {% if item.dependence %}
    {% for dependence in item.dependence %}
    <li class="dependence">
        {% if url %}<a href="{{ dependence.url }}" title="{{ dependence.label|striptags|raw }}">{% endif %}{{ dependence.title|raw }}{% if url %}</a>{% endif %}
    </li>
    {% endfor %}
{% endif %}
</ul>
{% endif %}
{% endmacro %}

{% macro html_code(item) %}
{% if url %}<a href="{{ item.url }}" title="{{ item.label|striptags|raw }}">{% endif %}
<b>#{{ item.code }}</b>
{% if url %}</a>{% endif %}
{% endmacro %}

{% macro html_date(item, src, url = true) %}
{% if url %}<a href="{{ item.url }}" title="{{ item.label|striptags|raw }}">{% endif %}
<i class="fa fa-clock-o"></i> {{ item[src]|raw }}
{% if url %}</a>{% endif %}
{% endmacro %}

{% macro html_amount(item) %}
{% if item.amount and item.amount != '0,00' %}
<button class="btn btn-primary{% if url %} btn-click{% endif %}" {% if url %}data-link="{{ item.url }}"{% endif %} title="{{ item.label|striptags|raw }}">R$ {{ item.amount|raw }}</button>
{% endif %}
{% endmacro %}

{% macro html_text(item, label = 'text', charCrop = true) %}
{% if item[label] %}
{% if charCrop %}<p><a href="{{ item.url }}" title="{{ item[label]|striptags|raw}}">{% endif %}{{ item[label]|raw }}{% if charCrop %}</a></p>{% endif %}
{% endif %}
{% endmacro %}

{% macro html_button(item, label = 'Leia mais', btnClass = 'btn btn-xs btn-primary') %}
<a href="{{ item.url }}" class="{{ btnClass }}" title="{{ label|striptags|raw }}">{{ label|raw }}</a>
{% endmacro %}
