{% extends 'courseset-manage/courseset-layout.html.twig' %}
{% import 'macro.html.twig' as macro %}

{% block title %}{{'course.question_manage'|trans}} - {{ parent() }}{% endblock %}

{% set parentId = parentQuestion.id|default(0) %}

{% set side_nav = 'question' %}
{% do script(['app/js/question-manage/index.js',]) %}

{% block main %}

 {% set questionTypes = getQuestionTypes() %}

  <div role="courseset-manage-question">
    <div class="courseset-manage-body__title">
      <div class="courseset-manage-body__btn">
        {{ slot('course_set.questions_import_btn.extension', {'courseSet': courseSet}) }}
        {% for type,name in questionTypes %}
          {% if loop.index <= 3 %}
            <a href="{{ path('course_set_manage_question_create',{id:courseSet.id,type:type,parentId:parentId, goto:app.request.server.get('REQUEST_URI')}) }}" class="cd-btn cd-btn-info cd-btn-sm"><i class="cd-icon cd-icon-add cd-text-sm"></i>{{ name|trans }}</a>
          {% endif %}
        {% endfor %}
        <div class="btn-group">
        <a href="#" type="button" class="cd-btn cd-btn-default cd-btn-sm dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
        <ul class="dropdown-menu pull-right">
          {% for type,name in questionTypes %}
            {% if loop.index > 3 and ((type == 'material' and not parentQuestion) or type != 'material') %}
              <li><a href="{{ path('course_set_manage_question_create',{id:courseSet.id,type:type,parentId:parentId, goto:app.request.server.get('REQUEST_URI')}) }}"><span class="es-icon es-icon-anonymous-iconfont"></span> {{ name|trans }}</a></li>
            {% endif %}
          {% endfor %}
        </ul>
      </div>

      </div>
      {{'course.question_manage.content_title'|trans}}
    </div>

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

      {% if parentQuestion %}
        <ol class="breadcrumb">
          <li><a href="{{ path('course_set_manage_question',{id:courseSet.id}) }}">{{ 'course.question_manage.content_title'|trans }}</a></li>
          <li class="active">{{ dict_text('questionType', 'material') }}</li>
        </ol>
      {% endif %}

      {{ web_macro.flash_messages() }}

      {% if parentQuestion %}
        <div class="row">
          <div class="col-sm-12">
            <div class="well well-sm short-long-text">
              <div class="short-text">{{ parentQuestion.stem|plain_text(100) }} <span class="trigger">({{'site.btn.expand'|trans}})</span></div>
              <div class="long-text">{{ parentQuestion.stem|raw }} <span class="trigger">({{'site.btn.collapse'|trans}})</span></div>
            </div>
          </div>
        </div>
      {% endif %}

      {% if not parentQuestion %}
        {% include 'question-manage/search-form.html.twig' %}
      {% endif %}

      <table class="table table-striped table-hover" id="quiz-table">
        <thead>
        <tr>
          <th><input type="checkbox"  autocomplete="off"  data-role="batch-select"></th>
          <th width="45%">{{'course.question_manage.stem'|trans}}</th>
          <th width="15%">{{'course.question_manage.type'|trans}}</th>
          <th>{{'course.question_manage.update'|trans}}</th>
          <th width="15%">{{'course.question_manage.operation'|trans}}</th>
        </tr>
        </thead>
        <tbody>
          {% for question in questions %}
            {% include 'question-manage/question-tr.html.twig' %}
          {% else %}
            <tr>
              <td colspan="20"><div class="empty">{{'course.question_manage.empty'|trans}}</div></td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
      <div>
        <label class="checkbox-inline"><input type="checkbox"  autocomplete="off" data-role="batch-select"> {{'course.question_manage.select_all'|trans}}</label>
        <button class="cd-btn cd-btn-default cd-btn-sm mlm" data-role="batch-delete"  data-name="{{'course.question_manage.question'|trans}}" data-url="{{ path('course_set_manage_question_deletes',{courseSetId:courseSet.id}) }}" data-loading-text="{{'form.btn.delete.submiting'|trans}}">{{'form.btn.delete'|trans}}</button>
        <span class="pull-right color-gray">{{'course.question_manage.count'|trans({'%getItemCount()%': paginator.getItemCount() })}}</span>
      </div>
      <nav class="text-center">
        {{ web_macro.paginator(paginator) }}
      </nav>
    </div>
  </div>

{% endblock %}
