{% extends 'course/course-show.html.twig' %}
{% block title %} {{thread.title}} - {{ parent() }}{% endblock %}
{% do script(['libs/es-ckeditor/ckeditor.js','libs/jquery-validation.js','app/js/course/thread-show/index.js'])%}

{% set nav = 'threads' %}

{% block detail_content %}

  <ul class="breadcrumb">
    <li><a href="{{ path('my_course_show', {id: course.id, 'tab': 'threads'}) }}">{{'讨论区'|trans}}</a></li>
    <li class="active">{% if thread.type == 'question' %}{{'问答'|trans}}{% else %}{{'话题'|trans}}{% endif %}</li>
  </ul>

  <div class="thread">
    <div class="thread-header">
      {{ web_macro.user_avatar(author, 'pull-right') }}
      <h2 class="thread-title">
        {% if thread.type == 'question' %}
        <span class="label label-info">{{'问'|trans}}</span>
        {% endif %}
        {{ thread.title }}
      </h2>
      <div class="thread-metas">
        By {{  web_macro.user_link(author, 'link-primary') }}
        <span class="bullet mhs">•</span>
        {{ thread.createdTime|smart_time }}
        <span class="bullet mhs">•</span>
        {{'%hitNum%次浏览'|trans({'%hitNum%': thread.hitNum})}}
        {% if task|default(null) %}
          <span class="bullet mhs">•</span>
          <a class="link-primary" href="{{ path('course_task_show', {courseId: thread.courseId, id:thread.taskId}) }}" title="{{task.title}}">{{'任务%number%'|trans({'%number%': task.seq})}}</a>
        {% endif %}

      </div>
    </div>
    <div class="thread-body">{{ thread.content|raw }}</div>

    {% include 'attachment/widget/list.html.twig' with {targetType:'course.thread', targetId:thread.id} %}

    {% if isManager or app.user.id == author.id %}
      <div class="thread-footer" >
        <a href="{{ path('course_thread_edit', {courseId:thread.courseId, threadId:thread.id}) }}" class="btn btn-link"><span class="glyphicon glyphicon-edit"></span> {{'编辑'|trans}}</a>
        {% if isManager %}
          <a href="javascript:;" class="btn btn-link" data-url="{{ path('course_thread_delete', {courseId:course.id, threadId:thread.id}) }}" data-after-url="{{ path('my_course_show', {id:course.id, tab: 'threads'}) }}" data-role="confirm-btn" data-confirm-message="{{'您真的要删除该帖吗？'|trans}}"><span class="glyphicon glyphicon-remove-sign"></span> {{'删除'|trans}}</a>
          {% if thread.isStick %}
            <a href="javascript:" class="btn btn-link" data-url="{{ path('course_thread_unstick', { courseId:course.id, threadId:thread.id}) }}" data-role="confirm-btn" data-confirm-message="{{'您真的要取消置顶该帖吗？'|trans}}"><span class="glyphicon glyphicon-minus-sign"></span> {{'取消置顶'|trans}}</a>
          {% else %}
            <a href="javascript:" class="btn btn-link" data-url="{{ path('course_thread_stick', {courseId:course.id, threadId:thread.id}) }}" data-role="confirm-btn" data-confirm-message="{{'您真的要置顶该帖吗？'|trans}}"><span class="glyphicon glyphicon-circle-arrow-up"></span> {{'置顶'|trans}}</a>
          {% endif %}

          {% if thread.isElite %}
            <a href="javascript:" class="btn btn-link" data-url="{{ path('course_thread_unelite', {courseId:course.id, threadId:thread.id}) }}"data-role="confirm-btn" data-confirm-message="{{'您真的要取消加精该帖吗？'|trans}}"><span class="glyphicon glyphicon-hand-right"></span> {{'取消加精'|trans}}</a>
          {% else %}
            <a href="javascript:" class="btn btn-link" data-url="{{ path('course_thread_elite', {courseId:course.id, threadId:thread.id}) }}"data-role="confirm-btn" data-confirm-message="{{'您真的要加精该帖吗？'|trans}}"><span class="glyphicon glyphicon-thumbs-up"></span>  {{'加精'|trans}}</a>
          {% endif %}
        {% endif %}
      </div>
    {% endif %}
  </div>

  <div class="thread-posts">
    {% if thread.type == 'question' and elitePosts %}
      <h3 class="thread-posts-heading"><span class="glyphicon glyphicon-share-alt"></span> {{'教师的答案'|trans}}</h3>
      <ul class="thread-post-list media-list">
        {% for post in elitePosts %}
          {% set author = users[post.userId] %}
          {% include 'course/thread/post-list-item.html.twig' %}
        {% endfor %}
      </ul>
    {% endif %}

    <h3 class="thread-posts-heading">
      <span class="glyphicon glyphicon-share-alt"></span>
      <span id="thread-post-num">{{ thread.postNum }}</span> {% if thread.type == 'question' %}{{'所有答案'|trans}}{% else %}{{'回复'|trans}}{% endif %}
    </h3>

    <ul class="thread-post-list media-list">
      {% for post in posts %}
        {% set author = users[post.userId] %}
        {% include 'course/thread/post-list-item.html.twig' %}
      {% else %}
        <li class="empty">{{'还没有'|trans}}{% if thread.type == 'question' %}{{'答案'|trans}}{% else %}{{'回复'|trans}}{% endif %}，{{'赶快添加一个吧！'|trans}}</li>
      {% endfor %}
    </ul>

    {{ web_macro.paginator(paginator) }}

    {% if isMemberNonExpired %}
      <h3 class="thread-posts-heading"><span class="glyphicon glyphicon-plus"></span> {{'添加'|trans}}{% if thread.type == 'question' %}{{'答案'|trans}}{% else %}{{'回复'|trans}}{% endif %}</h3>
      {{ render(controller('AppBundle:Course/Thread:post', {courseId:course.id, threadId:thread.id})) }}
    {% endif %}

  </div>

{% endblock %}