{% extends 'TopxiaWebBundle::bootstrap-modal-layout.html.twig' %}

{% set modal_class = 'modal-lg' %}

{% block title %}<span class="text-muted">免费课时预览:</span> {{lesson.title}}{% endblock %}

{% block body %}
	{% if lesson.status == 'published' %}

	  {% if lesson.mediaSource == 'iframe' %}
      <div id="lesson-preview-iframe" data-url="{{ lesson.mediaUri }}" style="display:none;">
      </div>
		{% elseif lesson.type == 'video' %}
			{% if lesson.mediaSource == 'self' %}
				<div id="lesson-preview-video-player" data-url="{{ path('course_lesson_media', {courseId:lesson.courseId, lessonId:lesson.id}) }}" data-hls-url="{{ hlsUrl }}"
                    {% if setting('storage.video_watermark') and setting('storage.video_watermark_image') %}
                        data-watermark="{{ filepath(setting('storage.video_watermark_image'), null, true) }}"
                    {% endif %}
                    {% if setting('storage.video_fingerprint') and app.user %}
                        data-fingerprint="{{ url('cloud_video_fingerprint', {userId:app.user.id}) }}"
                    {% endif %}

                >
                </div>
                <input type="hidden" id="videoWatermarkEmbedded" value="{{ hasVideoWatermarkEmbedded }}">
            {% else %}
                <div id="lesson-preview-swf-player" data-url="{{ lesson.mediaUri }}"></div>
            {% endif %}
        {% elseif lesson.type == 'audio' %}
            <audio id="lesson-preview-audio-player" width="100%" height="100%">
                 <source src="{{ path('course_lesson_media', {courseId:lesson.courseId, lessonId:lesson.id}) }}" type='audio/mp3' />
            </audio>
        {% elseif lesson.type == 'ppt' %}
            <div id="lesson-preview-ppt-player" data-url="{{ path('course_lesson_ppt', {courseId:lesson.courseId, lessonId:lesson.id}) }}" class="lesson-preview-ppt"></div>
        
        {% elseif lesson.type == 'document' %}

            <div id="lesson-preview-doucment" data-url="{{ path('course_lesson_document', {courseId:lesson.courseId, lessonId:lesson.id}) }}" {% if setting('magic.doc_watermark') %}data-watermark-url="{{ path('cloud_doc_watermark') }}" {% endif %}></div>
        {% else %}
            <div {% if setting('course.copy_enabled')|default(0) > 0 %} oncopy="return false;" oncut="return false;" onselectstart="return false" oncontextmenu="return false;"{% endif %}>
                {{ lesson.content|raw }}
            </div>
        {% endif %}
    {% else %}
        <div class="empty">课时尚未发布，无法预览！</div>
    {% endif %}
        <script>app.load('course/lesson-preview')</script>
{% endblock %}

{% block footer %}
{% if is_plugin_installed('Classroom') %}
    {% if lesson.status == 'published' %}
        {% if course.price=='0.00'  %}
                <a id="buy-btn" type="button" class="btn btn-primary" 
                {% if setting("course.buy_fill_userinfo")|default(false) %}
                href="#modal" 
                data-toggle="modal" 
                data-url="{{ path('course_buy', {id:course.id, targetType:'course'}) }}"
                {% else %}
                href="{{ path('order_show', {targetId:course.id, targetType:'course'}) }}"
                {% endif %}
                >
                    {% if user.id %}免费加入学习
                    {% else %}登录后加入学习
                    {% endif %}
                </a>
        {% else %}
                <a id="buy-btn" type="button" class="btn btn-primary" 
                {% if setting("course.buy_fill_userinfo")|default(false) %}
                href="#modal" 
                data-toggle="modal" 
                data-url="{{ path('course_buy', {id:course.id, targetType:'course'}) }}"
                {% else %}
                href="{{ path('order_show', {targetId:course.id, targetType:'course'}) }}"
                {% endif %}
                >
                    {% if user.id %}觉得不错？点击购买此课程（{{ course.price }}元）
                    
                    {% else %}登录后购买学习完整的课程
                    {% endif %}
                </a>
        {% endif %}
        {% endif %}
    {% else %}
        <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
    {% endif %}
{% endblock %}