{% macro boolean(value) %}
    {% if value %}
        {% trans %}bool.true{% endtrans %}
    {% else %}
        {% trans %}bool.false{% endtrans %}
    {% endif %}
{% endmacro %}

{% macro attachment_icon(attachment, attachment_helper, class = "fa-fw fas fa-3x", link = true) %}
    {% if not attachment_helper or attachment_helper.fileExisting(attachment) %}
        <a target="_blank"  data-no-ajax rel="noopener" href="{% if link %}{{ attachment|entityURL('file_view') }}{% endif %}">
            {% if attachment.picture %}
                <img class="hoverpic" src="{{ attachment|entityURL('file_view') }}">
            {% else %}
                <i class="text-dark {{ class }} {{ ext_to_fa_icon(attachment.extension) }}"></i>
            {% endif %}
        </a>
    {% elseif not attachment_helper.fileExisting(attachment) %}
        <i class="{{ class }} fa-exclamation-triangle text-danger"></i>
    {% endif %}
{% endmacro %}

{% macro string_to_tags(string, class="badge badge-info") %}
    {% for tag in string|split(',') %}
        <a href="{{ url('part_list_tags', {'tag': tag | trim}) }}" class="{{ class }}" >{{ tag | trim }}</a>
    {% endfor %}
{% endmacro %}

{% macro m_status_to_badge(status, class="badge") %}
    {% if status is not empty %}
        {% set color = " badge-secondary" %}

        {% if status == "active" %}
            {% set color = " badge-success" %}
        {% elseif status == "nrfnd" %}
            {% set color = " badge-warning" %}
        {% elseif status == "eol" %}
            {% set color = " badge-warning" %}
        {% elseif status == "discontinued" %}
            {% set color = " badge-danger" %}
        {% endif %}

        <span class="{{ class ~ color}}" title="{{ ("m_status." ~ status ~ ".help") | trans }}">
            <i class="fa-fw fas fa-info-circle"></i>
            {{ ("m_status." ~ status) | trans }}
        </span>
    {% endif %}
{% endmacro %}

{% macro structural_entity_link(entity, link_type = "list_parts") %}
    {# @var entity \App\Entity\Base\StructuralDBElement #}
    {% if entity %}
        <ul class="structural_link d-inline">
            {% for e in entity.pathArray %}
                <li>
                    {% if link_type is not empty and e.id is not null %}
                        <a href="{{ e | entityURL(link_type) }}">{{ e.name }}</a>
                    {% else %}
                        {{ e.name }}
                    {% endif %}
                </li>
            {% endfor %}
        </ul>
    {% else %}
        -
    {% endif %}
{% endmacro %}

{% macro breadcrumb_entity_link(entity, link_type = "list_parts") %}
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            {% for e in entity.pathArray %}
                <li class="breadcrumb-item {% if loop.last %}active{% endif %}">
                    {% if link_type is not empty and not loop.last and e.id is not null %}
                        <a href="{{ e | entityURL(link_type) }}">{{ e.name }}</a>
                    {% else %}
                        {{ e.name }}
                    {% endif %}
                </li>
            {% endfor %}
        </ol>
    </nav>
{% endmacro %}

{% macro bool_icon(bool) %}
    {% if bool %}
        <i class="fas fa-check-circle fa-fw" title="{% trans %}Yes{% endtrans %}"></i>
    {% else %}
        <i class="fas fa-times-circle fa-fw" title="{% trans %}No{% endtrans %}"></i>
    {% endif %}
{% endmacro %}