<?php include_once('header.php'); 
if(empty($_SESSION['login_id']))
redirect('login.php');

$sela=executework("SELECT * FROM  lms_instructor_courses where id='".$_GET['course_id']."'");
$cnta=@mysqli_num_rows($sela);
$rowa=@mysqli_fetch_array($sela);

$module=get_modules($_GET['course_id']);
$lessions=get_lessons($_GET['course_id'],'');
$purchange_status=get_cours_status($_SESSION['login_id'],$_GET['course_id']); 

$view_course=get_courses($_GET['course_id'],'','','','');
$cart_ids=get_cart_details();

if(in_array($view_course[0]['id'],$cart_ids))
$add=1;
else
$add=0;
?>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">

    <style>
        .course-header {
            background-color: #1c1d1f;
            color: white;
            padding: 40px 0;
        }
        .badge-premium { background-color: #eceb98; color: #1c1d1f; font-weight: bold; }
        
        .sticky-card {
            position: sticky;
            top: 20px;
            z-index: 1000;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        }
        .video-preview {
            background: #000;
            height: 200px;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
        }
        .play-btn { font-size: 3rem; color: white; cursor: pointer; }

        .learning-box { border: 1px solid #d1d7dc; padding: 24px; margin-top: 30px; }
        .accordion-button:not(.collapsed) { background-color: #f7f9fa; color: #1c1d1f; }
        
        .btn-purple { background-color: #a435f0; color: white; font-weight: bold; padding: 12px; border: none; }
        .btn-purple:hover { background-color: #8710d8; color: white; }
        
        .section-title { font-weight: 700; margin-bottom: 20px; }
    </style>


<div class="course-header mb-4">
    <div class="container">
        <div class="row">
            <div class="col-lg-8">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb mb-2" style="display:none">
                        <li class="breadcrumb-item"><a href="#" class="text-info text-decoration-none fw-bold">Development</a></li>
                        <li class="breadcrumb-item"><a href="#" class="text-info text-decoration-none fw-bold">Data Science</a></li>
                    </ol>
                </nav>
                <h1 class="fw-bold" style="color:#20c997"><?php echo $rowa['course_title']; ?></h1>
                <p class="fs-5"><?php  $result = strtoupper(str_replace('_', '', $rowa['course_type'])); echo $result; ?></p>
                <div class="d-flex align-items-center gap-2">
                    <span class="badge bg-warning text-dark">Bestseller</span>
                    <span class="text-warning fw-bold">4.6 <i class="bi bi-star-fill"></i><i class="bi bi-star-fill"></i><i class="bi bi-star-fill"></i><i class="bi bi-star-fill"></i><i class="bi bi-star-half"></i></span>
                </div>
                <div class="mt-2 small">
                    <i class="bi bi-globe ms-3"></i> <?php echo $rowa['language']; ?>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="container" style="margin-bottom:100px">
    <div class="row">
        <div class="col-lg-8">
            
            <div class="learning-box">
                <h3 class="section-title">Details</h3>
                <div class="row g-3">
                    <div class="col-md-12">
                        <div class="d-flex gap-2"><i class="bi bi-check2"></i> <span><?php echo $rowa['details']; ?></span></div>
                        
                    </div>
                    
                </div>
            </div>

            <div class="mt-5">
                <h3 class="section-title">Course content</h3>
                <div class="d-flex justify-content-between mb-2 small fw-bold">
                    <span> <?php echo count($module); ?> Modules • <?php echo count($lessions); ?> Topics </span>
                </div>

                <div class="accordion" id="courseAccordion">
                  <?php
					   for($i=0;$i<count($module);$i++)
					   {
						$lession_details=get_lessons($module[$i]['course_id'],$module[$i]['id']);  
					?>
                    <div class="accordion-item" style="margin-bottom:0px !important;">
                        <h2 class="accordion-header">
                            <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne<?php echo $i; ?>">
                           		<strong style="padding: 4px 10px; background-color: #2eca7f; color: white; border-radius: 50px;"><?php echo $i+1; ?></strong>
                                <strong> &nbsp; &nbsp;Intro to AI Module: Getting started</strong>
                                <span class="ms-auto me-3 small"><?php echo count($lession_details); ?> Topics </span>
                            </button>
                        </h2>
                        <div id="collapseOne<?php echo $i; ?>" class="accordion-collapse collapse <?php if($i==0){?>show <?php } ?>">
                            <div class="accordion-body p-0">
                                <ul class="list-group list-group-flush">
                                	<?php
										for($j=0;$j<count($lession_details);$j++)
										{
									?>
                                    <li class="list-group-item d-flex align-items-center justify-content-between">
                                        <span><i class="bi bi-play-circle-fill me-2"></i> <strong class="text-primary"> <?php echo $lessions[$j]['lesson_title']; ?> </strong></span> <br>
                                       
                                       	<?php if(count($purchange_status)>0){ ?>
                                        <a href="javascript:void(0);" class="small text-primary text-decoration-none view-video" data-bs-toggle="modal" data-bs-target="#videoModal" data-video="<?php echo $lession_details[$j]['video_url']; ?>"> <i class="bi bi-eye-fill"></i> View Video</a>
                                        <?php if(!empty($lession_details[$j]['material_upload'])){ ?>
                                       <a href="download.php?file=<?php echo $lession_details[$j]['material_upload']; ?>" class="small text-primary text-decoration-none"><i class="bi bi-download me-2"></i> Download Material</a>
                                       <?php } else { ?>
                                       	<span class="small text-danger"><i class="bi bi-download me-2 text-danger"></i> &nbsp; Not Data Found</span>
                                        <?php } ?>
                                        <span class="small text-primary"><i class="bi bi-clipboard-check"></i> Test</span>  
                                        <?php } ?>                    
                                    </li> 
                                    
                                   
                                    
                                   <?php } if(count($lession_details)==0){ ?>
                                     <li class="list-group-item d-flex align-items-center justify-content-between">
                                        <span class="text-danger"><i class="bi bi-circle-fill me-2"></i> No Data Found </span>
                                        <span class="small">10:16</span>
                                    </li>
                                   <?php } ?>
                                </ul>
                            </div>
                        </div>
                    </div>
					<?php } ?>
                    
                </div>
            </div>

           <div class="learning-box">
                <h3 class="section-title">Overview</h3>
                <div class="row g-3">
                    <div class="col-md-12">
                        <div class="d-flex gap-2"><i class="bi bi-check2"></i> <span><?php echo $rowa['course_overview']; ?></span></div>
                        
                    </div>
                </div>
            </div>
            <?php if(!empty($rowa['additional_info'])){ ?>
             <div class="learning-box">
                <h3 class="section-title">Additional Information</h3>
                <div class="row g-3">
                    <div class="col-md-12">
                        <div class="d-flex gap-2"><i class="bi bi-check2"></i> <span><?php echo $rowa['additional_info']; ?></span></div>
                        
                    </div>
                </div>
            </div>
            <?php } ?>

        </div>        

        <div class="col-lg-4">
            <div class="card sticky-card">
                <div class="video-preview" style="padding:16%; background-color:black">
                		<center> <a href="javascript:void(0);" class="small text-primary text-decoration-none view-video" data-bs-toggle="modal" data-bs-target="#videoModal" data-video="<?php echo $rowa['course_video']; ?>"> <i class="bi bi-play-circle-fill me-2 text-light" style="font-size:40px"></i></a>
                    	 </center>
                    <div class="position-absolute bottom-0 text-white p-2 fw-bold">Preview this course</div>
                </div>
                <div class="card-body">
                    <div class="nav nav-tabs mb-3" role="tablist">
                        <button class="nav-link active w-50 fw-bold" data-bs-toggle="tab">Personal</button>
                        <!--<button class="nav-link w-50 fw-bold" data-bs-toggle="tab">Teams</button>-->
                    </div>
                    <?php if(!empty($rowa['course_discount'])){ ?>
                    <h3 class="fw-bold mb-4">$<?php $discount=$rowa['course_price']/100 *$rowa['course_discount']; echo $rowa['course_price']-$discount; ?> <span class="fs-6 text-decoration-line-through text-muted">$<?php echo $rowa['course_price']; ?></span></h3>
                    <?php } else { ?>
                    <h3 class="fw-bold mb-4">$<?php echo $rowa['course_price']/100 *$rowa['course_discount']; ?></h3>
                    <?php } ?>
                    <!--<p class="text-danger small mb-3 fw-bold">84% off • 5 days left at this price!</p>-->
                    
                   <?php /*?> <button class="btn btn-purple w-100 mb-2">Start subscription</button>
                    <p class="text-center small text-muted">Starting at ₹500.00/month after trial</p>
                    
                    
                    
                    <button class="btn btn-outline-dark w-100 mb-3 fw-bold">Buy individual course</button>
                    
                    <div class="text-center small mb-3">30-Day Money-Back Guarantee</div><?php */?>
                    
                    <?php if(count($purchange_status)<=0){ ?>
                    
                    <?php 	if(empty($_SESSION['login_id']))
                        {
					?>
                      <a href="login.php" class="custom-button theme-one" >Enroll Now <i class="fa fa-angle-right"></i></a>
                    <?php }  else{ ?>
                       <a class="custom-button theme-one cart_main_add<?php echo $view_course[0]['id']; ?>" style="cursor:pointer" onclick="add_to_cart('<?php echo $view_course[0]['id']; ?>','<?php echo $_SESSION['login_id']; ?>','add')" >Enroll Now <i class="fa fa-angle-right"></i></a>
						
                       <a class="custom-button theme-one cart_main_remove<?php echo $view_course[0]['id']; ?>" style="background-color:#2eca7f; cursor:pointer" onClick="add_to_cart('<?php echo $view_course[0]['id']; ?>','<?php echo $_SESSION['login_id']; ?>','remove');" >Remove <i class="fa fa-angle-right"></i></a>
                    <?php } ?>
                    
                    <?php } ?>
                    
                    <div class="input-group mb-3" style="display:none">
                        <input type="text" class="form-control" placeholder="Enter Coupon" value="CM060406IN">
                        <button class="btn btn-dark" type="button">Apply</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

 <div class="modal fade" id="videoModal" tabindex="-1" aria-hidden="true">
     <div class="modal-dialog modal-lg modal-dialog-centered">
         <div class="modal-content bg-dark">
           <div class="modal-header border-0">
          		<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
           </div>
          <div class="modal-body p-0">
            <div class="ratio ratio-16x9">
                <iframe id="mainVideoPlayer" src="" allowfullscreen allow="autoplay"></iframe>
            </div>
        </div>
       </div>
     </div>
 </div>
 
<script>toggle_cart('<?php echo $view_course[0]['id']; ?>','<?php echo $add; ?>');</script>
                         
<?php include_once('footer.php'); ?>

<script>
document.addEventListener('DOMContentLoaded', function () {
    var videoModal = document.getElementById('videoModal');
    var videoPlayer = document.getElementById('mainVideoPlayer');

    videoModal.addEventListener('show.bs.modal', function (event) {
        var button = event.relatedTarget;
        var videoSrc = button.getAttribute('data-video');

        if (videoSrc) {
            let videoId = '';

            if (videoSrc.includes("watch?v=")) {
                videoId = videoSrc.split("watch?v=")[1];
            } 
            else if (videoSrc.includes("youtu.be/")) {
                videoId = videoSrc.split("youtu.be/")[1];
            }
            else if (videoSrc.includes("shorts/")) {
                videoId = videoSrc.split("shorts/")[1];
            }

            if (videoId.includes("&")) {
                videoId = videoId.split("&")[0];
            }

            videoPlayer.src = "https://www.youtube.com/embed/" + videoId + "?autoplay=1";
        }
    });

    videoModal.addEventListener('hide.bs.modal', function () {
        videoPlayer.src = "";
    });
});
</script>



