<?php error_reporting(0) ?>
<div class="content-wrapper">
   <section class="content-header">
      <div class="container-fluid">
         <div class="row mb-2">
            <div class="col-sm-6">
               <h1>My Course</h1>
            </div>
            <div class="col-sm-6">
               <ol class="breadcrumb float-sm-right">
                  <li class="breadcrumb-item"><a href="<?php echo admin_url() ?>admin">Home</a></li>
                  <li class="breadcrumb-item active">My Course</li>
               </ol>
            </div>
         </div>
      </div>
   </section>

   <section class="content my-course-1-full-body">
      <div class="container-fluid">
         <div class="card card-default">
            <div class="card-body">
               <div class="card-body p-0">
                  <div class="row text-dark">
                     <?php //foreach ($enrolments as $enrolment):
                     $course_details = $this->course_model->get_course_by_id_for_lms(user()->course)->row_array();
                     // $instructor_details = $this->user_model->get_all_user($course_details['creator'])->row_array();
                     $course_duration = $this->course_model->get_total_duration_of_lesson_by_course_id($course_details['course_id']);
                     $lectures = $this->db->get_where('lesson', ['course_id' => $course_details['course_id'], 'lesson_type !=' => 'quiz']);
                     $quizzes = $this->db->get_where('lesson', ['course_id' => $course_details['course_id'], 'lesson_type' => 'quiz']);
                     $watch_history = $this->course_model->get_watch_histories($this->session->userdata('user_id'), $course_details['course_id'])->row_array();
                     $course_progress = isset($watch_history['course_progress']) ? $watch_history['course_progress'] : 0;
                     ?>
                     <div class="col-lg-12 col-md-12 col-sm-6 col-12 mb-5">
                        <div class="my-course-1-full-body-card">
                           <div class="my-course-1-img">
                              <img loading="lazy" src="<?php echo base_url(); ?><?php echo $course_details['course_image'] ?>" alt="">
                           </div>
                           <div class="my-course-1-text pt-1">
                              <div class="my-course-1-text-heading">
                                 <h3><?php echo $course_details['course_heading']; ?></h3>
                                 <div class="child-icon">
                                    <div class="dropdown">
                                       <button class="btn btn-secondary dropdown-toggle py-0" type="button" id="dropdownMenuButton2" data-bs-toggle="dropdown" aria-expanded="false">
                                          <i class="fa-solid fa-ellipsis-vertical"></i>
                                       </button>
                                       <ul class="dropdown-menu dropdown-menu-dark dropdown-menu-end" aria-labelledby="dropdownMenuButton2">
                                          <li>
                                             <a class="dropdown-item py-2" href="<?php echo base_url() ?>/course/<?php echo $course_details['course_slug'] ?>"><?php echo get_phrase('Go to course page') ?></a>
                                          </li>
                                          <li>
                                             <a class="dropdown-item py-2" href="<?php echo base_url() ?>/course/<?php echo $course_details['course_slug'] ?>"><?php echo get_phrase('Author profile') ?></a>
                                          </li>
                                       </ul>
                                    </div>
                                 </div>
                              </div>
                              <div class="my-course-1-lesson-text mb-2">
                                 <div class="icon-1">
                                    <p><i class="far fa-play-circle"></i> <?php echo get_phrase('Lectures') . ' ' . $lectures->num_rows(); ?></p>
                                 </div>
                                 <div class="icon-1">
                                    <p><i class="far fa-question-circle"></i> <?php echo get_phrase('Quizzes') . ' ' . $quizzes->num_rows(); ?></p>
                                 </div>
                                 <div class="icon-1">
                                    <p><i class="fa fa-clock"></i> <?php echo $course_duration; ?></p>
                                 </div>
                              </div>
                              <div class="my-course-1-skill">
                                 <div class="skill-bar-container">
                                    <div class="skill-bar" style="width: <?php echo $course_progress; ?>%; animation: unset"></div>
                                 </div>
                                 <p><?php echo $course_progress; ?>%</p>
                              </div>

                              <?php //include 'live_class_scadule.php'; ?>

                              <div class="my-course-1-last">
                                 <div class="icon-img d-grid">
                                    <?php $my_rating = $this->course_model->get_user_specific_rating('course', $course_details['course_id']); ?>
                                    <div class="d-flex align-items-center">
                                       <img loading="lazy" class="ms-0" src="<?php //echo $this->user_model->get_user_image_url($this->session->userdata('user_id')); 
                                                                              ?>" alt="">
                                       <span class="text-14px ms-1 mt-1"><?php //echo $instructor_details['first_name'] . ' ' . $instructor_details['last_name']; 
                                                                           ?> </span>
                                       <div class="star m-0">
                                          <?php for ($i = 1; $i <= 5; $i++): ?>
                                             <i class="fa fa-star <?php if ($my_rating['rating'] >= $i) echo 'gold'; ?>"></i>
                                          <?php endfor; ?>
                                       </div>
                                    </div>
                                    <?php if ($enrolment['expiry_date'] > 0 && $enrolment['expiry_date'] < time()): ?>
                                       <span class="text-12px text-start mt-2"><?php echo get_phrase('Expired') ?> - <b style="color: var(--bs-code-color);"><?php echo date('d M Y, H:i A', $enrolment['expiry_date']); ?></b></span>
                                    <?php else: ?>
                                       <?php if ($enrolment['expiry_date'] == 0): ?>
                                          <span class="text-12px text-start mt-2"><?php echo get_phrase('Expiry period') ?> - <b class="text-success text-uppercase"><?php echo get_phrase('Lifetime Access'); ?></b></span>
                                       <?php else: ?>
                                          <span class="text-12px text-start mt-2"><?php echo get_phrase('Expiration On') ?> - <b><?php echo date('d M Y, H:i A', $enrolment['expiry_date']); ?></b></span>
                                       <?php endif; ?>
                                    <?php endif; ?>
                                 </div>
                                 <div class="my-course-1-btn pt-4 me-4">
                                    <?php if ($enrolment['expiry_date'] > 0 && $enrolment['expiry_date'] < time()): ?>
                                       <a class="btn text-14px py-1 text-white" style="background-color: var(--bs-code-color);" href="#" onclick="actionTo('http://localhost/academy/academy_6.0/home/handle_buy_now/<?php echo $course_details['course_id']; ?>')">
                                          <i class="far fa-calendar-plus"></i>
                                          <?php echo get_phrase('Join again'); ?>
                                       </a>
                                    <?php else: ?>
                                       <a class="btn btn-primary text-14px py-1" href="<?php echo site_url('admin/admin/lesson/' . $course_details['course_slug'] . '/' . $course_details['course_id']) 
                                                                                       ?>">
                                          <i class="far fa-play-circle"></i>
                                          <?php echo get_phrase('Start Now'); ?>
                                       </a>
                                    <?php endif; ?>
                                 </div>
                              </div>
                           </div>
                        </div>
                     </div>
                     <?php //endforeach; 
                     ?>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </section>
</div>
<style>
   .my-course-1-full-body .my-course-1-full-body-card:last-child {
      border-bottom: none;
      padding-bottom: 0;
      margin-bottom: 0;
      display: flex;
      cursor: pointer;
   }

   .my-course-1-full-body .my-course-1-full-body-card .my-course-1-img img {
      height: 143px;
      width: 245px;
      object-fit: cover;
      border-radius: 10px;
   }

   .my-course-1-full-body .my-course-1-full-body-card .my-course-1-text {
      width: 100%;
      margin-left: 26px;
   }

   .my-course-1-full-body .my-course-1-full-body-card .my-course-1-text .my-course-1-text-heading {
      display: flex;
      justify-content: space-between;
   }

   .my-course-1-full-body .my-course-1-full-body-card .my-course-1-text .my-course-1-text-heading .child-icon i {
      margin-top: 0;
   }

   .my-course-1-lesson-text img {
      width: 12px;
      height: 12px;
      margin-top: 3px;
   }

   .my-course-1-lesson-text i {
      font-size: 12px;
      color: #6E798A;
      font-weight: 600;
      margin-top: 2px;
   }

   .my-course-1-lesson-text {
      display: flex;
      margin-bottom: 12px;
   }

   .my-course-1-lesson-text .icon-1 {
      display: flex;
   }

   .my-course-1-lesson-text .icon-1 p {
      font-size: 12px;
      margin-left: 8px;
   }

   .my-course-1-lesson-text .icon-1 {
      margin-right: 30px;
      margin-top: 8px;
   }

   .my-course-1-last .my-course-1-btn .btn {
      /* background-color: var(--color-4); */
      padding: 5px 28px;
      display: block;
   }

   .my-course-1-last .my-course-1-btn .btn a {
      text-decoration: none;
      color: #fff;
      font-size: 12px;
      font-weight: 500;
   }

   .my-course-1-last {
      display: flex;
      justify-content: space-between;
   }

   .my-course-1-last .icon-img {
      display: flex;
   }

   .my-course-1-last .icon-img img {
      height: 30px;
      width: 30px;
      margin-left: 16px;
      border-radius: 50%;
   }

   .my-course-1-last .icon-img .star i {
      color: #6E798A4D;
      height: 12px;
      width: 12px;
      margin-left: 5px;
      font-size: 12px;
   }

   .my-course-1-last .icon-img .star {
      margin-top: 3px;
   }

   .my-course-1-last .icon-img .star .gold {
      color: #FFD43B;
   }

   .my-course-1-skill {
      display: flex;
   }

   .my-course-1-skill p {
      margin-left: 15px;
      margin-top: -9px;
      font-size: 12px;
   }

   /* Skill Bar */
   .skill-bar-container {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      background-color: #6E798A33;
      border-radius: 10px;
      height: 5px;
      width: 88%;
   }

   .skill-bar {
      height: 5px;
      background-color: var(--color-4);
      border-radius: 10px;
      margin-right: 10px;
      width: 0;
      animation: fill-bar 2s ease-out forwards;
   }

   .skill-bar-label {
      font-weight: bold;
   }


   @keyframes fill-bar {
      0% {
         width: 0;
      }

      100% {
         width: 30%;
      }
   }
</style>