{% set mode = mode|default('default') %}
<ul class="course-grids">
  {% for course in courses %}
    <li class="course-grid">
      <a href="{{ path('course_show', {id:course.id}) }}" class="grid-body">
        <img src="{{ default_path('coursePicture',course.largePicture, 'large') }}"  class="img-responsive thumb">
          {% if course.status == 'draft' %}
            <span class="label  label-warning course-status">未发布</span>
          {% elseif course.status == 'closed' %}
            <span class="label label-danger course-status">已关闭</span>
          {% endif %}
          {% if course.status != 'closed' %} 
            {% if course.serializeMode=='serialize' %}
              <span class="label label-success series-mode-label">更新中</span>
            {% elseif course.serializeMode=='finished' %}
              <span class="label label-warning series-mode-label">已完结</span>
            {% endif %}
          {% endif %}
          {% if course.type == 'live' %}
            {% set lesson = course['lesson']|default(null) %}
            {% if lesson and "now"|date("U") >= lesson.startTime and "now"|date("U") <= lesson.endTime %}
              <span class="label label-warning series-mode-label">正在直播中</span>
            {% else %}
              <span class="label label-success series-mode-label">直播</span>
            {% endif %}
          {% endif %}

        <span class="title" style="overflow:hidden;height:52px">{{ course.title }}</span>

        {% set user = users[course.teacherIds|first]|default(null) %}
        {% if user %}
          <a href="{{path('user_show',{id:user.id})}}">
            <span class="teacher clearfix">
              <img src="{{ default_path('avatar',user.smallAvatar, '') }}" class="thumb">
              <span class="nickname ellipsis">{{ user.truename }}</span>
            </span>
          </a>
        {% endif %}
        {% if mode in ['default', 'teach'] %}

          {% if course.type == 'live' %}
            {% set lesson = course['lesson']|default(null) %}
            {% if lesson %}
              <span class="live-course-lesson metas">
                <span class="text-success mrm">{{ lesson.startTime|date('n月j日 H:i') }} ~ {{ lesson.endTime|date('H:i') }}</span>
                <span class="text-muted mrm">第{{ lesson.number }}课时</span>
              </span>
            {% endif %}
          {% endif %}

          {# <span class="metas clearfix">
            <span class="price-col">
              <span class="meta-label">价格</span>
              {% if course.price > 0 %}
                <span class="price-num">{{ course.price }}元</span>
              {% else %}
                <span class="price-num">免费</span>
              {% endif %}
            </span> #}

            {% if course.showStudentNumType == 'opened' %}
            <span class="student-col">
              <span class="meta-label">学生</span>
              <span class="student-num">{{ course.studentNum }}人</span>
            </span>
            {% endif %}

            <span class="review-col">
              {% if course.ratingNum > 0 %}
                <span class="meta-label"><strong>{{ course.ratingNum }}</strong> 评价</span>
                <span class="review-rating">
                  <span class="stars-{{ (course.rating)|number_format }}">&nbsp;</span>
                </span>
              {% else %}
                <span class="meta-label">无评价</span>
                <span class="review-rating">
                  <span class="stars-0">&nbsp;</span>
                </span>
              {% endif %}
            </span>

          </span>
        {% endif %}

        {% if mode in ['default'] %}
          {% set user = users[course.teacherIds|first]|default(null) %}
          {% if user %}
            <span class="teacher clearfix">
              <img src="{{ default_path('avatar',user.smallAvatar, '') }}" class="thumb">
              <span class="nickname ellipsis">{{ user.truename }}</span>
              <span class="user-title ellipsis">{{ user.title }}</span>
            </span>
          {% endif %}
        {% endif  %}

        {% if mode in ['learn'] %}
          {% if app.user.isParent() %}
            <div class="learn-status">
              {% if course.memberIsLearned %}
                <div class="progress">
                  <div class="progress-bar progress-bar-success" style="width: 100%;"></div>
                </div>
              {% else %}
                <div class="progress">
                  <div class="progress-bar progress-bar-success" style="width: {{ percent(course.memberLearnedNum, course.lessonNum) }};"></div>
                </div>
              {% endif %}
            </div>
          {% else %}
            <div class="learn-status">
              {% if course.memberIsLearned %}
                <div class="progress">
                  <div class="progress-bar progress-bar-success" style="width: 100%;">学习总时长: {{course.learnTime}}</div>
                </div>
                
                <div class="action"><a href="{{ path('course_show', {id:course.id}) }}"><span class="btn btn-default btn-sm">查看课程</span></a></div>
              {% else %}
                <div class="progress">
                  <div class="progress-bar progress-bar-success" style="width: {{ percent(course.memberLearnedNum, course.lessonNum) }};"></div>
                </div>
                <div class="action"><a href="{{ path('course_show', {id:course.id}) }}"><span class="btn btn-primary btn-sm">继续学习</span></a></div>
              {% endif %}
            </div>   
          {% endif %}
        {% endif %}

        {% if mode == 'teach' %}
          {% if course.status == 'published' %}
            <span class="label label-success course-status">已发布</span>
          {% elseif course.status == 'draft' %}
            <span class="label  label-warning course-status">未发布</span>
          {% elseif course.status == 'closed' %}
            <span class="label label-danger course-status">已关闭</span>
          {% endif %}
        {% endif %}

      </a>
    </li>
  {% endfor %}
</ul>