{# Template : Messages parent page #}
{% extends 'layouts/members.twig' %}

{% block members_content %}

    {% include 'includes/elements/intro_block.twig' with {
        intro_title: 'Messages',
        intro_content: 'Create and manage messages between you and our doctors or customer service.',
        class: 'membersIntro',
        use_h1: true
    }%}

    <div class="membersContentWrap">


        <div class="messageListWrap">

            <ul class="messageList">

                {% if threads is not empty %}

                {% for thread in threads %}

                    <li class="{% if thread.hasMemberUnread() is not empty %}notRead{% endif %}">

                        <a href="/members/messages/view_thread.php?thread={{ thread.url }}" class="view">


                            {{ thread.getLatestMessageAttribute().text|striptags|truncate(50, true, "...")|raw }}

                            {% if thread.hasMemberUnread() is not empty %}
                                <span class="unreadCount">{{ thread.memberUnreadCount() }}</span>
                            {% endif %}

                            <i class="fal fa-eye"></i>

                        </a>

                    </li>

                {% endfor %}

            </ul>

            <div class="newThreadContainer">
                <a class="button" href="/members/messages/new.php" title="New Message">
                    New thread
                </a>
            </div>

            {% else %}

                <p>No message threads found.</p>

                <div class="newThreadContainer">
                    <a class="button" href="/members/messages/new.php" title="New Message">
                        New thread
                    </a>
                </div>

            {% endif %}

        </div> <!-- .messageListWrap -->

        {% if email_history is not empty %}

            <div class="emailListWrap">

                <div class="membersEmailSection">

                    <div class="emailBoxHeader">

                        <h5 class="memberTitle">Email notification history</h5>
                        <p>
                            This section lists all email notifications we have sent to you.
                        </p>

                    </div><!-- .emailBoxHeader -->

                    <ul class="messageList smallList">


                        {% for notification in email_history %}

                            <li>
                                <span>
                                    {{ notification.created_at.format('d/m/Y H:i') }} -
                                    {{ notification.subject }}
                                </span>
                            </li>

                        {% endfor %}


                    </ul>
                </div><!-- .membersEmailSection -->

            </div> <!-- .emailListWrap -->

        {% endif %}


    </div> <!-- .membersContentGrid -->

{% endblock %}
