{% extends 'open-course-manage/layout.html.twig' %}
{% block title %}{{'推荐设置'|trans}} - {{ parent() }}{% endblock %}
{% set side_nav = 'marketing' %}
{% do script(['app/js/open-course-manage/recommend-course/index.js'])%}


{% block main %}

<style>

.course-grid {
    display: inline-block;
    vertical-align: top;
    margin: 15px 15px 15px 0;
    border: 1px solid #e1e1e1;
    border-radius: 4px;
}

.course-grid .add-course {
    font-size: 80px;
    height: 148px;
    text-align: center;
    padding-top: 30px;
}
.sort{
    padding-top: 50px;
    padding-right: 20px;
    padding-left: 20px;
}

.price{
  color: #e57259;
  font-size: 16px;
}
</style>

<div class="panel panel-default panel-col">
  <div class="panel-heading">{{'推荐设置'|trans}}
    <button class="btn btn-success btn-sm panel-bar" data-toggle="modal" data-target="#modal" data-url="{{path('open_course_manage_course_pick', {id:course['id']})}}">添加课程</button>
  </div>

  <div class="panel-body">
    <form class="form-horizontal" id="recommend-course-form" method="post" action="{{ path('open_course_manage_marketing',{id:course.id}) }}">
      {% set openCourse = course %}
      {{ web_macro.flash_messages() }}

      <div class="form-group" id="courses-form-group">
        <div class="col-md-12 controls">
          <ul class="course-list-group sortable-list course-wide-list courses-selected" id="course-list-group" data-role="list" >

            {% for recommendId, courseSet in courseSets %}
              {% set showUrl = path('course_show',{id: courseSet.defaultCourseId}) %}

              <li class="course-item item-{{courseSet.id}} clearfix" data-role="item" >
                <input type="hidden" name="recommendIds[]" value="{{ recommendId }}" />
                
                <span class="glyphicon glyphicon-resize-vertical sort-handle sort"></span>
                <a class="course-picture-link" href="{{ showUrl }}" target="_blank">
                  <img class="course-picture" src="{{ filepath(course_set_cover(courseSet, 'middle'), 'courseSet.png') }}" alt="{{ courseSet.title }}">
                </a>

                <button class="close delete-btn pull-right mrl mts mll" data-role="item-delete" type="button" title="删除" style="font-size:35px;" data-cancel-url="{{ path('open_course_manage_recommend_course_delete', {id:openCourse.id, recommendId: recommendId}) }}" data-recommend-id="{{ recommendId }}" data-id="{{courseSet.id}}">× </button>

                <div class="course-body">
                  <div style="float:right;" class="color-gray mrm mls">
                    {% include 'open-course-manage/course-set-price-interval.html.twig' %}
                  </div>

                  <h4 class="course-title"><a href="{{ showUrl }}" target="_blank">{{ courseSet.title }}</a>
                  {% if courseSet.type == 'normal' or courseSet.type == 'live' %}
                    {% if courseSet.serializeMode=='serialized' %}
                      <span class="label label-success ">更新中</span>
                    {% elseif courseSet.serializeMode=='finished' %}
                      <span class="label label-warning ">已完结</span>
                    {% endif %}
                  {% endif %}

                  {% if courseSet.type == 'live' %}
                    {% set task = courseSet['task']|default(null) %}
                    {% if task and "now"|date("U") >= task.startTime and "now"|date("U") <= task.endTime %}
                      <span class="label label-warning">正在直播中</span>
                    {% else %}
                      <span class="label label-success">直播</span>
                    {% endif %}
                  {% endif %}
                  </h4>

                  {% if courseSet.type == 'live' %}
                    {% set task = courseSet.task|default(null) %}
                    {% if task %}
                      <div class="live-course-lesson mbm">
                        <span class="color-success fsm mrm">{{ task.startTime|date('n月j日 H:i') }} ~ {{ task.endTime|date('H:i') }}</span>
                        <span class="color-gray fsm mrm">第{{ task.number }}任务</span>
                      </div>
                    {% endif %}
                  {% else %}
                    <div class="course-about ellipsis">{{ course.subtitle }}</div>
                  {% endif %}

                  <div class="course-footer clearfix">
                    {% set teacher = users[courseSet.teacherIds|first|default(courseSet.creator)] %}
                    {% if teacher %}
                      <div class="teacher">
                        <a href="{{ path('user_show', {id:teacher.id}) }}" target="_blank"><img src="{{ filepath(teacher.smallAvatar, 'avatar.png') }}" class="teacher-avatar"></a>
                        <a class="teacher-nickname ellipsis" target="_blank"  href="{{ path('user_show', {id:teacher.id}) }}">{{ teacher.nickname }}</a>
                        <span class="teacher-title ellipsis">{{ teacher.title }}</span>
                      </div>
                    {% endif %}

                    <div class="course-metas">  

                      {% if setting('course.show_student_num_enabled', '1') == 1  %}
                        <span class="color-gray text-sm">{{ courseSet.studentNum }}{{setting('default.user_name', '学员')}}</span>
                        {#<span class="divider"></span>#}
                      {% endif %}  

                      {#<span class="color-gray text-sm">
                          {{course.lessonNum}}个任务
                      </span>#}
                      {#{% if course.type == 'normal' or course.type == 'live' %}
                        <span class="divider"></span>
                       
                        <span class="color-gray text-sm">
                          有效期:
                          {% if course.expiryDay %}
                            {{course.expiryDay}}天
                          {% else %}
                            永久
                          {% endif %}
                        </span>
                      {% endif %}#}
                    </div>

                  </div>

                </div>
              </li>

            {% endfor %}

          </ul>
        </div>  
      </div>

      {% if courseSets %}
        <div class="form-group">
          <div class="col-md-offset-9 col-md-3 controls">
            <button type="submit" class="btn btn-fat btn-primary pull-right">保存修改</button>
          </div>  
        </div>
      {% else %}
        <div class="empty">赶紧添加课程吧！</div>
      {% endif %}

      <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">

    </form>
  </div>
</div>

{% endblock %}