<?php wp_enqueue_script( 'ulp_public_instructor_actions', ULP_URL . 'assets/js/instructor_actions.js', [], false, false );?>
<h3><?php _e('Lessons', 'ulp');?></h3>

<div class="ulp-instructor-dashboard-bttn">
    <a href="<?php echo $addNewLink;?>" class="btn btn-primary pointer"><?php _e('Add New Lesson', 'ulp');?></a>
</div>

<?php if ($items):?>

<div class="ulp-instructor-dashboard-lesson-list ulp-instructor-dashboard-list">
    <div class="ulp-instructor-item-list-head">
     <div class="ulp-instructor-item-list-row">
        <div class="ulp-instructor-item-list-col ulp-instructor-item-list-title"><?php _e('Title', 'ulp');?></div>
        <div class="ulp-instructor-item-list-col ulp-instructor-item-list-course"><?php _e('Course', 'ulp');?></div>
        <div class="ulp-instructor-item-list-col ulp-instructor-item-list-duration"><?php _e('Duration', 'ulp');?></div>
        <div class="ulp-instructor-item-list-col ulp-instructor-item-list-rewards"><?php _e('Rewards', 'ulp');?></div>
        <div class="ulp-instructor-item-list-col ulp-instructor-item-list-date"><?php _e('Date', 'ulp');?></div>
     </div>
    </div>
     <div class="ulp-instructor-item-list-content">
        <?php foreach ($items as $key=>$post):?>
            <?php $object = new UlpLesson($post->ID, TRUE);?>
            <?php
      				$row_class ='';
      				if ($key%2 == 0) $row_class = 'even';
      				else $row_class = 'odd';
      			?>
            <div class="ulp-instructor-item-list-row <?php echo $row_class;?>">
               <div class="ulp-instructor-item-list-col ulp-instructor-item-list-title">
                    <i class="fa-ulp fa-ulp_lesson-ulp"></i><span class="ulp-instructor-item-list-name"><a href="<?php echo \Ulp_Permalinks::getForLesson($post->ID);?>" target="_blank"><?php echo $post->post_title;?></a></span>
                     —
                    <span class="ulp-instructor-item-list-status-<?php echo $post->post_status;?>"><?php echo ucfirst($post->post_status);?></span>
                    <div  class="ulp-instructor-item-list-options">
                        <span><a href="<?php echo add_query_arg(['tab' => 'add-edit', 'type' => 'ulp_lesson','postId' => $post->ID], $baseUri);?>"><?php _e('Edit', 'ulp');?></a></span> |
                        <span><a href="<?php echo add_query_arg(['tab' => 'special-settings', 'type' => 'ulp_lesson','postId' => $post->ID], $baseUri);?>"><?php _e('Special settings', 'ulp');?></a></span> |
                        <span class="js-ulp-do-delete-post ulp-delete-link" data-post="<?php echo $post->ID;?>"><?php _e('Delete', 'ulp');?></span> |
						<span><a href="<?php echo \Ulp_Permalinks::getForLesson($post->ID);?>" target="_blank"><?php _e('View', 'ulp');?></a></span>
                    </div>
                </div>
                <div class="ulp-instructor-item-list-col ulp-instructor-item-list-course">
                    <?php
                    $course_id = $object->LessonParent();
                    if ($course_id){
                      $course_label = DbUlp::getPostTitleByPostId($course_id);
                      if ($course_label){
                          echo '<div class="ulp-instructor-item-list-course-name">'.$course_label.'</div>';
                      } else {
                          echo '-';
                      }
                    } else {
                      echo '-';
                    }
                    ?>
                </div>
                <div class="ulp-instructor-item-list-col ulp-instructor-item-list-duration">
                  <?php
                      $types = ulp_get_time_types();
                      $duration = $object->Duration();
                      if ($duration && isset($types[$object->DurationType()])){
                        echo $duration . ' ' . $types[$object->DurationType()];
                      } else {
                        echo __('Not set', 'ulp');
                      }
                  ?>
                </div>
                <div class="ulp-instructor-item-list-col ulp-instructor-item-list-rewards">
                    <?php
                				$points = $object->RewardPoints();
                				if($points > 0){
                            echo $points.__(' points', 'ulp');
                        } else {
                            echo '-';
                        }
                    ?>
                </div>
                <div class="ulp-instructor-item-list-col ulp-instructor-item-list-date">
                    <?php echo ulp_print_date_like_wp($post->post_date, FALSE);?>
                </div>
           </div>
        <?php endforeach;?>
     </div>
 </div>
<?php endif;?>

<?php if ($pagination):?>
    <?php echo $pagination;?>
<?php endif;?>
