{% extends 'admin/layout.html.twig' %}

{% set menu = 'admin_message' %}
{% set script_controller = 'message/list' %}

{% block main %}
  <div class="well well-sm">
    <form id="message-search-form" class="form-inline" action="" method="get" novalidate>
      <div class="form-group">
        <input class="form-control" type="text" id="startDate" name="startDate"
               value="{{ app.request.query.get('startDate') }}" placeholder="{{'admin.user.form.input_placeholder.startDate'|trans}}">
      </div>

      <div class="form-group">
        <input class="form-control" type="text" id="endDate" name="endDate"
               value="{{ app.request.query.get('endDate') }}" placeholder="{{'admin.user.form.input_placeholder.endDate'|trans}}">
      </div>
      <span></span>
      <div class="form-group">
        <input type="text" id="nickname" name="nickname" value="{{ app.request.query.get('nickname') }}"
               class="form-control" placeholder="{{ 'admin.user.message.nickname.input_placeholder'|trans }}">
      </div>

      <div class="form-group">
        <input type="text" id="content" name="content" value="{{ app.request.query.get('content') }}"
               class="form-control" placeholder="{{'admin.user.message.content.input_placeholder'|trans}}">
      </div>

      <button class="btn btn-primary">{{'admin.user.form.btn.search_submit_btn'|trans}}</button>
    </form>
  </div>

  <div id="message-table-container">

  <table class="table table-striped table-hover" id="message-table">
    <thead>
      <tr >
        <th width="10%"> <input type="checkbox"  data-role="batch-select"> {{'admin.user.message.fields.sender_label'|trans}}</th>
        <th width="10%">{{'admin.user.message.fields.receiver_label'|trans}}</th>
        <th width="45%">{{'admin.user.message.fields.content_label'|trans}}</th>
        <th width="15%">{{'admin.user.message.fields.send_time_label'|trans}}</th>
      </tr>
      </thead>
      <tbody>
      {% if messages %}
        {% for message in messages %}
          <tr class="message-tr" id="message-table-tr-{{ message.id }}">
            <td><input value="{{ message.id }}" type="checkbox" data-role="batch-item">
              {{ admin_macro.user_link(users[message.fromId]) }}
            </td>

            <td>{{ admin_macro.user_link(users[message.toId]) }} </td>
            <td>
              <div class="short-long-text">
                <div class="short-text text-sm text-muted">{{ message.content|plain_text(60) }} <span class="trigger">{{ 'admin.user.message.fields.content_spread_label'|trans }}</span>
                </div>
                <div class="long-text">{{ message.content }} <span class="trigger">{{ 'admin.user.message.fields.content_retract_label'|trans }}</span></div>
              </div>
            </td>
            <td>{{ message.createdTime|date('Y-n-d H:i') }}</td>
          </tr>
        {% endfor %}
      {% else %}
        <tr>
          <td colspan="20">
            <div class="empty">{{ 'admin.user.message.empty_hint'|trans }}</div>
          </td>
        </tr>
      {% endif %}

      </tbody>
    </table>
    <div>
      <label class="checkbox-inline"><input type="checkbox" data-role="batch-select">{{ 'admin.user.message.fields.check_all_label'|trans }}</label>
      <button class="btn btn-default btn-sm mlm" data-role="batch-delete" data-name="{{ 'admin.user.message.delete_btn.data_name'|trans }}"
              data-url="{{ path('admin_message_delete_messages') }}">{{ 'admin.user.message.delete_btn'|trans }}
      </button>
    </div>

  </div>

  <div>
    {{ admin_macro.paginator(paginator) }}
  </div>

{% endblock %}
