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

{% set script_controller = 'course/threads' %}

{% set menu = 'admin_course_thread_manage' %}

{% block main %}

<div class="well well-sm">
  <form class="form-inline">
    <div class="form-group">
      <select class="form-control" name="type">
        {{ select_options(dict('threadType'), app.request.get('type'), 'admin.course_thread.course_thread_manage_tab.form.type_option'|trans) }}
      </select>
    </div>
    
    <span class="divider"></span>

    <div class="form-group">
      <select class="form-control" name="threadType">
        {{ select_options({isStick:'admin.course_thread.course_thread_manage_tab.form.thread_type.isStick_option'|trans, isElite: 'admin.course_thread.course_thread_manage_tab.form.thread_type.isElite_option'|trans}, app.request.get('threadType'), 'admin.course_thread.course_thread_manage_tab.form.thread_type_option'|trans) }}
      </select>
    </div>

    <span class="divider"></span>

    <div class="form-group">
      <select class="form-control" name="keywordType">
        {{ select_options({title:'admin.course_thread.form.keyword_type.title_option'|trans, content: 'admin.course_thread.form.keyword_type.content_option'|trans, courseId:'admin.course_thread.form.keyword_type.courseId_option'|trans, courseTitle:'admin.course_thread.form.keyword_type.courseTitle_option'|trans}, app.request.get('keywordType')) }}
      </select>
    </div>

    <div class="form-group">
      <input class="form-control" type="text" placeholder="{{'admin.course_thread.form.input.keyword.placeholer'|trans}}" name="keyword" value="{{ app.request.get('keyword') }}">
    </div>

    <div class="form-group">
      <input class="form-control" type="text" placeholder="{{'admin.course_thread.form.input.author.placeholer'|trans}}" name="author" value="{{ app.request.get('author') }}">
    </div>

    <button class="btn btn-primary" type="submit">{{'form.btn.search'|trans}}</button>
  </form>
</div>

  <div id="thread-table-container">
    <table class="table table-striped table-hover">
      <thead>
        <tr>
          <th width="5%"><input type="checkbox" data-role="batch-select"></th>
          <th width="50%">{{'admin.course_thread.post_th'|trans}}</th>
          <th width="10%">{{'admin.course_thread.reply_or_review_th'|trans}}</th>
          <th width="10%">{{'admin.course_thread.type_th'|trans}}</th>
          <th width="15%">{{'admin.course_thread.author_th'|trans}}</th>
          <th width="10%">{{'admin.course_thread.operation_th'|trans}}</th>
        </tr>
      </thead>
      <body>
        {% for thread in threads %}
          {% set author = users[thread.userId]|default(null) %}
          {% set courseSet = courseSets[thread.courseSetId]|default(null) %}
          {% set course = courses[thread.courseId]|default(null) %}
          {% set task = tasks[thread.taskId]|default(null) %}
          {% if thread.type == 'question' and thread.title == '' %}
            {% if thread.questionType == 'video' %}
              {% set questionType = 'course.thread.question_type.video'|trans %}
            {% elseif thread.questionType == 'image' %}
              {% set questionType = 'course.thread.question_type.image'|trans %}
            {% elseif thread.questionType == 'audio' %}
              {% set questionType = 'course.thread.question_type.audio'|trans %}
            {% elseif thread.questionType == 'content' %}
              {% set questionType = 'course.thread.question_type.content'|trans %}
            {% endif %}
          {% endif %}
          <tr data-role="item">
            <td><input value="{{thread.id}}" type="checkbox" data-role="batch-item"> </td>
            <td>
              {% if thread.type == 'question' %}
                <span class="label label-info">{{'admin.course_thread.question_td_label'|trans}}</span>
              {% endif %}

              <a href="{{ path('course_thread_show', {courseId:thread.courseId, threadId:thread.id}) }}" target="_blank"><strong>{{ thread.title|default('course.thread.question.title'|trans({'%questionType%':questionType|default('course.thread.question_type.content'|trans)}))  }}</strong></a>

              <div class="short-long-text">
                <div class="short-text text-sm text-muted">{{ thread.content|plain_text(60) }} <span class="trigger">({{'admin.course_thread.expand_td'|trans}})</span></div>
                <div class="long-text">{{ thread.content|raw }} <span class="trigger">({{'admin.course_thread.collapse_td'|trans}})</span></div>
              </div>
              
              <div class="text-sm mts">
                {% if courseSet %}
                  <a href="{{ path('course_show', {id:courseSet.defaultCourseId}) }}" class="text-success" target="_blank">{{ courseSet.title }}</a>
                {% endif %}

                {% if course %}
                  <span class="text-muted mhs">&raquo;</span>
                  <a href="{{ path('course_show', {id:course.id}) }}" class="text-success" target="_blank">{{ course.title }}</a>
                {% endif %}

                {% if task %}
                  <span class="text-muted mhs">&raquo;</span>
                  <a class="text-success"  href="{{ path('course_task_show', {courseId:thread.courseId, id:task.id}) }}" target="_blank">{{ setting('course.task_name')|default('admin.setting_course.task'|trans) }}{{task.number}}：{{ task.title }}</a>
                {% endif %}
              </div>
            </td>
            <td><span class="text-sm">{{ thread.postNum }} / {{ thread.hitNum }}</span></td>
            <td>
              {% if course %}
                <a href="javascript:;" data-set-url="{{ path('course_thread_elite', {courseId:course.id, threadId:thread.id}) }}" data-cancel-url="{{ path('course_thread_unelite', {courseId:course.id, threadId:thread.id}) }}" class="promoted-label">
                  <span class="label {% if thread.isElite %}label-success{% else %}label-default{% endif %}">{{'admin.course_thread.course_thread_manage_tab.isElite_btn'|trans}}</span>
                </a>
              
                <a href="javascript:;" data-set-url="{{ path('course_thread_stick', {courseId:course.id, threadId:thread.id}) }}" data-cancel-url="{{ path('course_thread_unstick', {courseId:course.id, threadId:thread.id}) }}" class="promoted-label">
                  <span class="label {% if thread.isStick %}label-success{% else %}label-default{% endif %}">{{'admin.course_thread.course_thread_manage_tab.isStick_btn'|trans}}</span>
                </a>
              {% endif %}
            </td>
            <td>
              {{ admin_macro.user_link(author) }} <br />
              <span class="text-muted text-sm">{{ thread.createdTime|date('Y-n-d H:i:s') }}</span>
            </td>
            <td>
              <div class="btn-group">
                <a href="javascript:;" data-role="item-delete" data-url="{{ path('admin_thread_delete', {id:thread.id}) }}" class="btn btn-default btn-sm" 
                data-name="{{'admin.course_thread.post_th'|trans}}" >{{'form.btn.delete'|trans}}</a>
              </div>
            </td>
          </tr>
        {% else %}
          <tr><td colspan="20"><div class="empty">{{'site.datagrid.empty'|trans}}</div></td></tr>
        {% endfor %}
      </body>
    </table>

    <div class="mbm">
        <label class="checkbox-inline"><input type="checkbox" data-role="batch-select"> {{'admin.course_thread.select_all_btn'|trans}}</label>
        <button class="btn btn-default btn-sm mlm" data-role="batch-delete" data-name="{{'admin.course_thread.post_th'|trans}}" data-url="{{ path('admin_thread_batch_delete') }}">{{'form.btn.delete'|trans}}</button>
    </div>

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