<?php 

function cp_view_lesson_cb() {
	if(!isset($_GET['id'])) return_method();
	$post = new post;
	$lesson_meta = $post->get_post_meta($_GET['id']);
	switch ($lesson_meta['term']) {
		case 1:
			$term = "First Term";
			break;

		case 2:
			$term = "Second Term";
			break;

		case 3:
			$term = "Third Term";
			break;
		
		default:
			$term = "Not Available";
			break;
	}
	?>


	<div class="nav-wrapper">
	    <ul class="nav nav-pills nav-fill flex-column flex-md-row" id="tabs-icons-text" role="tablist">
	    	<li class="nav-item">
	            <a class="nav-link mb-sm-2 mb-md-0" id="tabs-icons-text-0-tab" data-toggle="tab" href="#stream-tab" role="tab" aria-controls="tabs-icons-text-2" aria-selected="false"><i class="fas fa-rss mr-2"></i>Stream</a>
	        </li>
	        <li class="nav-item">
	            <a class="nav-link mb-sm-3 mb-md-0 active" id="tabs-icons-text-1-tab" data-toggle="tab" href="#tabs-icons-text-1" role="tab" aria-controls="tabs-icons-text-1" aria-selected="true"><i class="ni ni-folder-17 mr-2"></i>Lesson Contents</a>
	        </li>
	        <li class="nav-item">
	            <a class="nav-link mb-sm-2 mb-md-0" id="tabs-icons-text-2-tab" data-toggle="tab" href="#comments-tab" role="tab" aria-controls="tabs-icons-text-2" aria-selected="false"><i class="ni ni-chat-round mr-2"></i>Comments</a>
	        </li>
	        <li class="nav-item">
	            <a class="nav-link mb-sm-3 mb-md-0" id="tabs-icons-text-3-tab" data-toggle="tab" href="#students-tab" role="tab" aria-controls="tabs-icons-text-3" aria-selected="false"><i class="ni ni-single-02 mr-2"></i>Students</a>
	        </li>
	    </ul>
	</div>
	<div class="card shadow">
		<div class="card-img-top-container">
			<img class="card-img-top" src="<?php echo cp_get_random_banner(); ?>" alt="Card image cap">
			<div class="card-labels">
				<h3><?php echo get_class_name($lesson_meta['class'])." ".get_course_name($lesson_meta['course']); ?></h3>
				<h2><?php echo $lesson_meta['topic'] ?></h2>
				<p><?php echo $term; ?>, Week <?php echo $lesson_meta['week']; ?> | Period: <?php echo $lesson_meta['period']; ?></p>
			</div>
		</div>
		
	    <div class="card-body">
	        <div class="tab-content" id="myTabContent">
	        	<div class="tab-pane fade" id="stream-tab" role="tabpanel" aria-labelledby="tabs-icons-text-2-tab">
	                <?php 
						render_page_content("cp-classwork-stream");
					 ?>
	            </div>
	            <div class="tab-pane fade show active" id="tabs-icons-text-1" role="tabpanel" aria-labelledby="tabs-icons-text-1-tab">
	            	<div class="row">
	            		<div class="col-12">
	            			<div class="cp-combo-box">
	            				<div class="cp-combo-box-header">
	            					<h2>Objectives</h2>
	            				</div>
	            				<div class="cp-combo-box-body">
	            					<div><?php echo $lesson_meta['objectives'] ?></div>
	            				</div>
	            			</div>
	            			<div class="cp-combo-box">
	            				<div class="cp-combo-box-header">
	            					<h2>Materials</h2>
	            				</div>
	            				<div class="cp-combo-box-body">
	            					<div id="materials" data-lesson_id="<?php echo $lesson_meta['id'] ?>"></div>
	            				</div>
	            			</div>
	            			<!-- <div class="cp-combo-box">
	            				<div class="cp-combo-box-header">
	            					<h2>Assignment</h2>
	            				</div>
	            				<div class="cp-combo-box-body">
	            					<div></div>
	            				</div>
	            			</div> -->
	            		</div>
	            	</div>
	            </div>
	            <div class="tab-pane fade" id="comments-tab" role="tabpanel" aria-labelledby="tabs-icons-text-2-tab">
	                <?php 
						do_action("comments_api", [
							'obj' => $lesson_meta['id'],
							'editor' => "",
							'key' => 'cp_view_lesson'
						])
					 ?>
	            </div>
	            <div class="tab-pane fade" id="students-tab" role="tabpanel" aria-labelledby="tabs-icons-text-3-tab">
	                <?php 
						$user = new user;
						$students = $user->get_user_by_meta_data(['role' => 'student', 'status' => 'active', 'class' => $lesson_meta['class']]);
						$table = new table("students-table", $students);
					    $table->set_display_columns([
					        "sn" => "SN",
					        "fullname" => "Name"
					    ]);
					    $table->display();
					 ?>
	            </div>
	        </div>
	    </div>
	</div>
	<?php
	global $post_meta;
	add_page_javascript('app/assets/js/page-scripts/js-functions.js');
	add_page_javascript('contents/plugins/classroom_plus/js/get-materials.js');
}