{#

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.

#}
{% extends sonata_block.templates.block_base %}

{% block block %}
    <div class="panel panel-default {{ settings.class }}">
        {% if settings.title is not empty %}
            <div class="panel-heading">
                <h4 class="panel-title">
                    {% if settings.icon %}
                        <i class="{{ settings.icon }}" aria-hidden="true"></i>
                    {% endif %}
                    {% if settings.translation_domain %}
                        {{ settings.title|trans({}, settings.translation_domain) }}
                    {% else %}
                        {{ settings.title }}
                    {% endif %}
                </h4>
            </div>
        {% endif %}

        <div class="panel-body">
            <ul class="timeline">
                {% for entry in entries %}
                    {% if currentDay is not defined or currentDay != entry.createdAt|format_date %}
                        {% set currentDay = entry.createdAt|format_date %}
                        <li class="time-label">
                            <span class="bg-red">{{ currentDay }}</span>
                        </li>
                    {% endif %}

                    {% set subject = entry.getComponent('subject') %}
                    {% set target = entry.getComponent('target') %}
                    {% set target_text_component = entry.getComponent('target_text') %}

                    {% if subject.data %}
                        {% set subject_text = sonata_timeline_generate_link(subject) %}
                    {% else %}
                        {% set subject_text %}
                            <abbr title="{{ 'element_reference_deleted'|trans({'%reference%': subject.hash}, "SonataTimelineBundle") }}">
                                {{ 'element_deleted'|trans({}, "SonataTimelineBundle") }}
                            </abbr>
                        {% endset %}
                    {% endif %}

                    {% if target.data is defined and target.data is not empty %}
                        {% set target_text = sonata_timeline_generate_link(target, entry) %}
                    {% elseif target_text_component %}
                        {% set target_text %}
                            <abbr title="{{ 'element_deleted'|trans({}, "SonataTimelineBundle") }}">
                                {{ target_text_component }}
                            </abbr>
                        {% endset %}
                    {% else %}
                        {% set target_text %}
                            <abbr title="{{ 'element_reference_deleted'|trans({'%reference%': target.hash}, "SonataTimelineBundle") }}">
                                {{ 'element_deleted'|trans({}, "SonataTimelineBundle") }}
                            </abbr>
                        {% endset %}
                    {% endif %}

                    {% set verb = "actions."~entry.verb %}
                    {% set icon = "actions.icon."~entry.verb %}

                    <li>
                        <i class="{{ icon|trans({}, "SonataTimelineBundle") }}"></i>
                        <div class="timeline-item" style="background: #f3f4f5;">
                            <span class="time">
                                <i class="fa fa-clock-o"></i> {{ entry.createdAt|format_time }}
                            </span>
                            <div class="timeline-body" style="border-bottom: none;">
                                {{ verb|trans({'%subject%': subject_text, '%target%': target_text}, "SonataTimelineBundle")|raw }}
                            </div>
                        </div>
                    </li>
                {% else %}
                    <p>{{ 'no_action'|trans({}, "SonataTimelineBundle") }}</p>
                {% endfor %}
            </ul>
        </div>
    </div>
{% endblock %}
