{% macro renderPager(pager, workspaceId) %}
    {{
        pagerfanta(
            pager,
            'twitter_bootstrap_translated',
            {
                'proximity' : 1,
                'routeName': 'claro_workspace_announcements_pager',
                'routeParams': {'workspaceId': workspaceId}
            }
        )
    }}
{% endmacro %}

{% from _self import renderPager %}

{% block javascripts %}
    <script
        src='{{ asset('bundles/clarolineannouncement/js/workspace_widget.js') }}'
        type="text/javascript"
    >
    </script>
{% endblock %}

{% set nbAnnouncements = datas|length %}

{% if nbAnnouncements > 0 %}
    {% set nbPages = datas.getNbPages() %}

    <div id="workspace-widget-pager" workspace-id="{{ workspaceId }}">

        {% if nbPages > 1 %}
            {{ renderPager(datas, workspaceId) }}
        {% endif %}
        <ul class="list-group">

            {% for data in datas %}
                <li class="list-group-item">
                    {% set title = data['announcement'].getTitle() %}

                    {% if title is not null %}
                        <h4 class="list-group-item-heading"><b>{{ title }}</b></h4>
                    {% endif %}
                    <div class="list-group-item-text">
                        {{ data['announcement'].getContent()|raw }}
                    </div>

                    <div class="list-group-item-text text-muted">
                        <small>
                            {{ 'published_on'|trans({}, 'announcement') }}
                            {{ data['announcement'].getPublicationDate().format('d-m-Y') }}
                            {% set announcer = data['announcement'].getAnnouncer() %}

                            {% if announcer is not null %}
                                {{ 'by'|trans({}, 'announcement') }}
                                <b>{{ announcer }}</b>
                            {% endif %}
                        </small>
                    </div>
                </li>
            {% endfor %}
        </ul>

        {% if nbPages > 1 %}
            {{ renderPager(datas, workspaceId) }}
        {% endif %}
    </div>
{% else %}
    {{ 'no_announcement_widget_message'|trans({}, 'widget') }}
{% endif %}