{% extends 'ClarolineCoreBundle:Message:layout.html.twig' %}

{% block title %}{% spaceless %}
    {% if ancestors | length >= 1 %}
        {{ parent() ~ ' - ' ~ ancestors[0].getObject() | striptags | raw }}
    {% else %}
        {{ 'new_message' | trans({}, 'platform') | striptags | raw }}
    {% endif %}
{% endspaceless %}{% endblock %}

{% block section_content %}
    <div class="row">
        <div class="col-md-6">
            {% for ancestor in ancestors %}
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class='panel-title'>{{ ancestor.getObject() | raw }}</h3>
                    </div>
                    <div class="panel-body">
                        <p class="text-muted">
                            {{ 'from_message'|trans({}, 'platform') }}:  {{ ancestor.getSenderUsername() }}
                        </p>
                        <div>
                            {% if ancestor.getSender() and ancestor.getSender().getPicture() != "" %}
                                <img src="{{ asset('uploads/pictures/') ~  ancestor.getSender().getPicture() }}" class="col-md-2" alt="{{ ancestor.getObject() }}">
                            {% endif %}
                        </div>
                        <p>
                            {{ ancestor.getContent()|raw }}
                            <p class="text-muted">
                                {{ ancestor.getDate()|timeAgo }}
                            </p>
                        </p>
                    </div>
                </div>
            {% endfor %}
        </div>
        <div class="col-md-{% if ancestors is empty %}12{% else %}6{% endif %}">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        {{ 'new_message'|trans({}, 'platform') }}
                    </h3>
                </div>
                <form role="form" novalidate="novalidate"
                    {% if message is empty %}
                        action="{{ path('claro_message_send', {'parentId': null}) }}"
                    {% else %}
                        action="{{ path('claro_message_send', {'parentId': message.getId()}) }}"
                    {% endif %}
                    method="post" {{ form_enctype(form) }}
                    id="generic-form"
                    class="form-horizontal">
                    <div class="panel-body">
                        {{ form_widget(form) }}
                        {{ form_rest(form) }}
                    </div>
                    <div class="panel-footer">
                        <button id="submit-button" type="submit" class="btn btn-primary">{{ 'send'|trans({}, 'platform') }}</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div id="contacts-box" class="modal fade" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h3>{{ 'select_contacts_title'|trans({}, 'platform') }}</h3>
                </div>
                <div class="modal-body">
                    <ul class="nav nav-tabs margin-bottom-md">
                        <li class="active" id="users-nav-tab">
                            <a href="#">
                                {{ 'users'|trans({}, 'platform') }}
                            </a>
                        </li>
                        <li id="groups-nav-tab">
                            <a href="#">
                                {{ 'groups'|trans({}, 'platform') }}
                            </a>
                        </li>
                        <li id="workspaces-nav-tab">
                            <a href="#">
                                {{ 'workspaces'|trans({}, 'platform') }}
                            </a>
                        </li>
                    </ul>
                    <br>
                    <div id="contacts-list"></div>
                </div>
                <div class="modal-footer">
                    <input type="button" id="add-contacts-confirm-ok" class="btn btn-primary" value="{{ 'ok'|trans({}, 'platform') }}"/>
                    <input type="button" class="btn btn-default" data-dismiss="modal" value="{{ 'cancel'|trans({}, 'platform') }}"/>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block javascripts %}
    {{ parent() }}
    <script src='{{ asset('bundles/clarolinecore/js/message/show.js') }}' type="text/javascript"></script>
{% endblock %}
