{% import 'macro.html.twig' as web_macro %}
{% set memberDeadline = member.deadline|default(0) %}
{% set isNewCoverSize = is_new_classroom_cover_size(classroom) %}

{# 区分角色 #}
<section class="class-header after {% if 'auditor' in member.role %} auditor{% endif %}">
  <div class="container">

    <ol class="breadcrumb breadcrumb-o">
      <li><a href="{{ path('homepage') }}">{{ 'homepage'|trans }}</a></li>
      {% for breadcrumb in breadcrumbs %}
        <li><a href="{{ path('classroom_explore',{'category':breadcrumb.code}) }}">{{ breadcrumb.name }}</a></li>
      {% endfor %}
      <li class="active">{{ classroom.title }}</li>
    </ol>

    {% if member.locked|default("0") == "1" %}
      <div class="alert alert-warning">
        {{ 'classroom.refund_tips'|trans }}
        <button class="btn btn-warning btn-sm cancel-refund" data-url="{{ path('order_cancel_refund', {orderId:member.orderId}) }}">
          {{ 'classroom.cancle_refund_btn'|trans }}
        </button>
      </div>
    {% endif %}

    {% if vipChecked|default('ok') != 'ok' %}
      <div class="alert alert-danger alert-dismissable">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
        {% if vipChecked == 'not_member' %}
          {{ 'classroom.not_vip_member_tips'|trans({'%classroomName%': setting("classroom.name")|default('classroom'|trans)})|raw }}
          {% if classroom.price > 0 %}
            {{ 'classroom.not_vip_member_and_become_vip_tips'|trans({'%vipUrl%': path('vip')})|raw }}
          {% else %}
            <a class="alert-link js-exit" href="javascript:;" data-url="{{ path('classroom_exit', { id:classroom.id }) }}">{{ 'classroom.exit'|trans }}</a>
          {% endif %}！
        {% elseif vipChecked == 'member_expired' %}
          {{ 'classroom.vip_member_expired_tips'|trans({'%classroomName%': setting("classroom.name")|default('classroom'|trans), '%vipRenewUrl%': path('vip_renew')})|raw }}
        {% elseif vipChecked == 'level_low' %}
          {{ 'classroom.vip_member_level_low_tips'|trans({'%classroomName%': setting("classroom.name")|default('classroom'|trans), '%vipUpgrade%': path('vip_upgrade')})|raw }}
        {% else %}
          {{ 'classroom.vip_checked_fail_tips'|trans({'%classroomName%': setting("classroom.name")|default('classroom'|trans)})|raw }}
          <a class="alert-link js-exit" href="javascript:" data-url="{{ path('classroom_exit', { id:classroom.id }) }}">{{ 'classroom.exit'|trans }}</a>
        {% endif %}
      </div>
    {% endif %}

    <div class="class-header-mian {% if isNewCoverSize %} class-header-main--new {% endif %}">
      {# 背景层即将舍弃 #}
      <div class="class-bg-layer"></div>
      <div class="class-header-bg clearfix">
        <div class="class-img">
          {# 分销标签 #}
          {{ slot('drp.product_tags.extension', {'type':'classroom','targetId':classroom.id}) }}
          <a href="{{ path('classroom_show',{id:classroom.id}) }}">
            <img src="{{ filepath(classroom.largePicture, 'classroom.png') }}" alt="{{ classroom.title }}">
          </a>
        </div>
        <div class="class-info">
          <h2 class="title class-info__title">
            <span class="hidden-xs">{{ classroom.title|sub_text(20) }}</span>
            <span class="visible-xs">{{ classroom.title }}</span>
            <span class="es-qrcode top" data-url="{{ path('classroom_qrcode',{id: classroom.id}) }}">
              <i class="es-icon es-icon-qrcode"></i>
              <span class="qrcode-popover">
                <img src="" alt="">
                {{ 'site.tips.scan_qrcode_tips'|trans }}
              </span>
            </span>
          </h2>
          <div class="metas class-info__metas mb0">
            {% if setting('classroom.show_review', '1') == 1 %}
              <div class="score">
                {{ web_macro.star(classroom.rating) }}
                <span>({{ classroom.ratingNum }}{{ 'classroom.reviews'|trans }})</span>
              </div>
            {% endif %}

            {% if 'auditor' in member.role %}
              <div class="price">
                {{ 'classroom.price'|trans }}：<span>
                  {% if setting('coin.coin_enabled') and setting('coin.price_type') == 'Coin' %}
                    {% if classroom.price > 0 %}
                      {{ classroom.price * setting('coin.cash_rate') }} {{ setting('coin.coin_name') }}
                    {% else %}
                      {{ 'classroom.price_free'|trans }}
                    {% endif %}
                  {% else %}
                    {% if classroom.price > 0 %}
                      {{ classroom.price }}{{ 'site.currency.CNY'|trans }}
                    {% else %}
                      {{ 'classroom.price_free'|trans }}
                    {% endif %}
                  {% endif %}
                </span>
              </div>
            {% endif %}
          </div>

          {% if classroom.expiryMode != 'forever' %}
            {% if 'student' in member.role or 'member' in member.role %}
              <div class="cd-text-xs hidden-sm cd-mb16">
                <span class="class-info__label">{{ 'classroom.expiryDays'|trans }}</span>
                <span>{{ memberDeadline|date('Y-m-d') }}</span>
              </div>
            {% endif %}
          {% endif %}

          <div class="class-info__serve class-serve hidden-sm hidden-xs">
            <div class="serve-label">{{ 'classroom.showServices'|trans }}</div>
            {% include 'classroom/service-block.html.twig' with {'services':classroom.service} %}
          </div>
        </div>

        <div class="class-operation">
          {# 班级过了有效期的提示 #}
          {% if (memberDeadline != 0 and date(memberDeadline) < date()) and ('student' in member.role or 'member' in member.role) %}
            <div class="class-deadline">
              {% if classroom.expiryMode == 'date' %}
                <div class="cd-alert cd-alert-warning mb0">{{ 'classroom.over_expiry_date_tips'|trans }}</div>
              {% elseif classroom.expiryMode == 'days' %}
                <div class="cd-alert alert-warning mb0">
                  <a class="cd-link-primary" href="{{ path('classroom_member_deadline_reach', {classroomId:classroom.id}) }}">
                    {% if classroom.buyable == 1 %}
                      {{ 'classroom.over_expiry_day_and_buyable_tips'|trans }}
                    {% else %}
                      {{ 'classroom.over_expiry_day_and_not_buyable_tips'|trans }}
                    {% endif %}
                  </a>
                </div>
              {% endif %}
            </div>
          {% endif %}

          <ul class="class-operation__data class-data clearfix {% if classroomMemberLevel and 'auditor' in member.role %}hidden-sm{% else %}two-col{% endif %}">
            {% if setting('classroom.show_student_num_enabled', '1') == 1 %}
              <li>
                <p><i class="es-icon es-icon-person"></i></p>
                <p>{{ 'site.default.student'|trans }}({{ classroom.studentNum + classroom.auditorNum }})</p>
              </li>
            {% endif %}
            <li>
              <span class="es-share top js-es-share">
                <a class="dropdown-toggle" href="javascript:;" data-toggle="dropdown" aria-labelledby="dropdownMenu1">
                  <p><i class="es-icon es-icon-share"></i></p>
                  <p>{{ 'site.btn.share'|trans }}</p>
                </a>
                {% include 'common/share-dropdown.html.twig' with {type: 'classroom'} %}
              </span>
            </li>

            {# 旁听生以及会员列 #}
            {% if 'auditor' in member.role and classroomMemberLevel and classroom.showable %}
              <li class="hidden-xs color-warning icon-vip" title="{{ 'classroom.vip_classroom'|trans({'%name%':setting('classroom.name')|default('classroom'|trans)}) }}"
                data-content="{% include 'course/header/parts/normal-header-vip.html.twig' with {courseVip:classroomMemberLevel,userVipStatus:checkMemberLevelResult} %}"
                data-original-title="{{ 'classroom.vip_classroom'|trans({'%name%':setting('classroom.name')|default('classroom'|trans)}) }}">
                <i class="es-icon es-icon-crown"></i><br>
                {% include 'course/header/parts/normal-header-vip-link.html.twig' with {userVipStatus:checkMemberLevelResult, level: classroomMemberLevel} %}
              </li>
            {% endif %}
          </ul>

          {# 旁听生说明以及购买 #}
          {% if 'auditor' in member.role %}
            <div class="class-operation__auditor hidden-sm clearfix">
              <span class="auditor-tip {% if classroom.status|default('draft') != 'published' %}auditor-tip--preview{% endif %}">
                {{ 'classroom.auditor_join_tips'|trans|raw }}
                <i class="es-icon es-icon-help color-primary" data-toggle="tooltip" data-placement="top" title="" data-original-title="{{ 'classroom.auditor_and_member_different_tips'|trans }}"></i>
              </span>
              {% if classroom.showable and classroom.status != 'closed' %}
                <div class="btn-buy pull-right">
                  {% include 'classroom/part/classroom-buy-btn.html.twig' with {isAuditor:true} %}
                </div>
              {% endif %}
            </div>
          {% endif %}
        </div>
        {#添加admin_v2#}
        {% if classroom_permit(classroom.id, 'Manage') and (has_permission('admin_classroom_content_manage') or has_permission('admin_v2_classroom_content_manage')) %}
            <a class="class-setting hidden-xs hidden-sm" href="{{ path('classroom_manage',{id:classroom.id}) }}"
            title="{{ 'classroom.classroom_manage'|trans({'%name%':setting('classroom.name')|default('classroom'|trans)}) }}">
            <i class="es-icon es-icon-setting"></i>
          </a>
        {% elseif classroom_permit(classroom.id, 'Handle') %}
          <a class="class-setting hidden-xs hidden-sm" href="{{ path('classroom_manage_testpaper', {id:classroom.id,status:'reviewing'}) }}"
            title="{{ 'classroom.classroom_manage'|trans({'%name%':setting('classroom.name')|default('classroom'|trans)}) }}">
            <i class="es-icon es-icon-setting"></i>
          </a>
        {% endif %}
        {# 退出班级 #}
        {% if 'student' in member.role or 'auditor' in member.role %}
          <a class="class-setting hidden-xs hidden-sm" data-toggle="modal" data-target="#modal" data-url="{{ path('course_exit_modal', {action:path('classroom_exit', {id:classroom.id})}) }}" href="javascript:;">
            <i class="es-icon es-icon-exit"></i>
          </a>
        {% endif %}

      </div>
    </div>
  </div>
</section>