<?php 
include_once('header.php');
$module=get_modules($_GET['course_id']);


$seltotal=executework("SELECT * FROM lms_instructor_lessons where course_id='".$_GET['course_id']."' and module_id='".$_GET['module_id']."' and status=1 and lesson_type='Video Lessons' and id='".$_GET['lesson_id']."'");
$cnttotal=@mysqli_num_rows($seltotal);
$rowtotal=@mysqli_fetch_array($seltotal);
?>
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">

<style>
/* Banner */
.banner {
    position: relative;
    height: 510px;
    border-radius: 20px;
    overflow: hidden;
    background: #111;
}

/* Video hidden initially */
#videoPlayer {
    display: none;
    width: 100%;
    height: 100%;
    border-radius: 20px;
}

/* Play Button */
.play-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 60px;
    cursor: pointer;
    transition: 0.3s;
}

.play-btn:hover {
    transform: translate(-50%, -50%) scale(1.2);
}

/* Chapters */
.chapter-scroll {
    display: flex;
    overflow-x: auto;
    gap: 10px;
}

.chapter-card {
    min-width: 140px;
    background: #111;
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: 0.3s;
}

.chapter-card:hover {
    background: #2563eb;
    transform: scale(1.05);
}

/* Floating Buttons */
.floating {
    position: fixed;
    bottom: 20px;
    right: 20px;
}

.floating .btn {
    display: block;
    margin-top: 10px;
    border-radius: 50px;
}

/* Progress Circle */
.circle {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: conic-gradient(#28a745 65%, #222 0%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.circle span {
    font-size: 18px;
}

@media(max-width:768px){
    .banner {
        height: 180px;
    }
}



/* Action Box */
.action-box {
    background: rgba(255,255,255,0.05);
    border-radius: 15px;
    backdrop-filter: blur(10px);
}

/* Cards */
.action-card {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    border-radius: 12px;
    text-decoration: none;
    color: white;
    transition: 0.3s;
    position: relative;
    overflow: hidden;
}

/* Icon */
.action-card .icon {
    font-size: 25px;
    padding: 10px;
    border-radius: 50%;
}

/* Download Style */
.download {
    background: linear-gradient(135deg, #00c6ff, #0072ff);
}

/* Test Style */
.test {
    background: linear-gradient(135deg, #28a745, #20c997);
}

/* Hover Animation */
.action-card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

/* Glow Effect */
.action-card::before {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.1);
    top: 0;
    left: -100%;
    transition: 0.4s;
}

.action-card:hover::before {
    left: 100%;
}
</style>



<!-- START SECTION TOP -->
<section class="section-top">
	<div class="container">
			
		
	<!-- END SECTION TOP -->

        <div class="container py-3">
        
            <!-- Banner -->
          <?php 
		  /*if($cnttotal!=0){ ?>
            <div class="banner mb-3">
        
                <!-- Dummy Video -->
                <?php if(!empty($rowtotal['video_url']))
							{ 
								echo $rowtotal['video_url'];
							} 
						else {
				  ?>
                <video id="videoPlayer" controls>
                   	 <source id="videoSource" src="../instructor/courses_upload/<?php  echo $rowtotal['video_upload']; ?>" >
                </video>
				  <?php } ?>        
                <!-- Play Button -->
                <div class="play-btn" id="playBtn" onclick="playVideo()">
                    <i class="bi bi-play-circle-fill"></i>
                </div>
        
            </div>
          <?php } 
		  	else { ?>
             	<div class="section-top-title wow fadeInRight" data-wow-duration="1s" data-wow-delay="0.3s" data-wow-offset="0"> <center> <h1>Video Not Available</h1> </center> </div>
         	<?php } */?>
            
            
            <?php 
				if($cnttotal!=0){
				
					// GET VIDEO SOURCE
					if(!empty($rowtotal['video_url'])){
						$video = trim($rowtotal['video_url']); // external link
					} else {
						$video = "../instructor/courses_upload/".$rowtotal['video_upload']; // uploaded file
					}
				
					echo '<div class="banner mb-3">';
				
					// ✅ YOUTUBE LINK
					if (strpos($video, 'youtube.com') !== false || strpos($video, 'youtu.be') !== false) {
				
						// Extract ID
						parse_str(parse_url($video, PHP_URL_QUERY), $params);
						$youtube_id = $params['v'] ?? '';
				
						if(empty($youtube_id)){
							$youtube_id = basename(parse_url($video, PHP_URL_PATH));
						}
				
						$embed = "https://www.youtube.com/embed/".$youtube_id;
						?>
				
						<iframe width="100%" height="100%" 
							src="<?php echo $embed; ?>" 
							frameborder="0" 
							allow="autoplay; encrypted-media" 
							allowfullscreen>
						</iframe>
				
						<?php
					}
				
					// ✅ MP4 FILE
					elseif (preg_match('/\.mp4$/i', $video)) {
						?>
				
						<video width="100%" height="100%" controls>
							<source src="<?php echo $video; ?>" type="video/mp4">
							Your browser does not support video.
						</video>
				
						<?php
					}
				
					// ❌ OTHER LINKS (NOT SUPPORTED)
					else {
						?>
				
						<div class="d-flex align-items-center justify-content-center h-100">
							<h4>❌ Invalid Video Link</h4>
						</div>
				
						<?php
					}
				
					echo '</div>';
				}
		  	else { ?>
             	<div class="section-top-title wow fadeInRight" data-wow-duration="1s" data-wow-delay="0.3s" data-wow-offset="0"> <center> <h1>Video Not Available</h1> </center> </div>
         	<?php } ?>
            
            
            <div class="action-box mt-4 p-3">

    <div class="row g-3">

        <!-- Download -->
        <div class="col-md-6">
            <a href="../instructor/courses_upload/<?php echo $rowtotal['material_upload']; ?>" 
               class="action-card download">
               
               <div class="icon">
                   <i class="bi bi-download"></i>
               </div>
               
               <div>
                   <h6>Download Material</h6>
                   <small>PDF / Notes</small>
               </div>

            </a>
        </div>

        <!-- Test -->
        <div class="col-md-6">
            <a href="test.php?course_id=<?php echo $_GET['course_id']; ?>&module_id=<?php echo $_GET['module_id']; ?>&lesson_id=<?php echo $_GET['lesson_id']; ?>" 
               class="action-card test">
               
               <div class="icon">
                   <i class="bi bi-pencil-square"></i>
               </div>

               <div>
                   <h6>Start Test</h6>
                   <small>Check your knowledge</small>
               </div>

            </a>
        </div>

    </div>

</div>
            
            
            <!-- Progress -->
            <div class="text-center mb-3" style="display:none">
                <div class="circle mx-auto">
                    <span id="progressText">65%</span>
                </div>
                <small>Completed</small>
            </div>
        
            <!-- Chapters -->
            <?php 
				$selsub=executework("SELECT * FROM lms_instructor_lessons where course_id='".$_GET['course_id']."' and module_id='".$_GET['module_id']."' and status=1 and id!='".$_GET['lesson_id']."'");
						$cnta=@mysqli_num_rows($selsub);
					
					if($cnta!=0){
			?>
            <h5>📚 Topics</h5>
            <div class="chapter-scroll mb-4 mt-4">
        		<?php 
						while($rowsub=@mysqli_fetch_array($selsub))
						{
					?>
                    <div class="chapter-card"> <a href="test.php?course_id=<?php echo $_GET['course_id']; ?>&module_id=<?php echo $_GET['module_id']; ?>&lesson_id=<?php echo $rowsub['id']; ?>" style="color:white"> <?php echo $rowsub['lesson_title']; ?> </a></div>
               <?php } ?>
        
            </div>
        	<?php } ?>
        </div>
        
        

    <!-- Floating Buttons -->
            <div class="floating">
                <a href="../instructor/courses_upload/<?php echo $rowtotal['material_upload']; ?>" class="btn btn-info">
                    <i class="bi bi-download"></i>
                </a>
            
                <button class="btn btn-success" onclick="startTest()">
                    <i class="bi bi-pencil-square"></i>
                </button>
            </div>
  </div><!--- END CONTAINER -->
</section>	
<script>
function playVideo() {
    document.getElementById("videoPlayer").style.display = "block";
    document.getElementById("playBtn").style.display = "none";
    document.getElementById("videoPlayer").play();
}

function changeVideo(src) {
    let video = document.getElementById("videoPlayer");
    let source = document.getElementById("videoSource");

    source.src = src;
    video.load();
    video.play();

    document.getElementById("videoPlayer").style.display = "block";
    document.getElementById("playBtn").style.display = "none";
}

function startTest() {
    alert("Test Started!");
}
</script>

<?php include_once('footer.php'); ?>
