<?php
get_header();
$sidebar    = themesflat_get_opt( 'courses_single_sidebar_list' );
$main_class = 'col-12';
if ( themesflat_get_opt( 'courses_single_layout' ) == 'sidebar-left' || themesflat_get_opt( 'courses_single_layout' ) == 'sidebar-right' ) {
	if ( is_active_sidebar( $sidebar ) ) {
		$main_class = 'col-lg-9';
	}
}
?>
<div class="container">
    <div class="wrap-content-area">
        <div id="primary" class="content-area">
            <main id="main" class="main-content" role="main">
                <div class="entry-content">
					<?php while ( have_posts() ) :
						the_post();
						$id         = get_the_ID();
						$curriculum = get_post_meta( $id, 'tf_course_curriculum', true );
						$id_image   = get_post_meta( $id, 'tf_course_instructor_avatar', true );
						$name       = get_post_meta( $id, 'tf_course_instructor_name', true );
						$position   = get_post_meta( $id, 'tf_course_instructor_position', true );
						$face       = get_post_meta( $id, 'tf_course_instructor_facebook', true );
						$twitter    = get_post_meta( $id, 'tf_course_instructor_twitter', true );
						$insta      = get_post_meta( $id, 'tf_course_instructor_instagram', true );
						$behance    = get_post_meta( $id, 'tf_course_instructor_behance', true );
						$url        = wp_get_attachment_url( $id_image );
						if ( empty( $url ) ) {
							$url = THEMESFLAT_LINK . 'images/placeholder.png';
						}
						?>
                        <div class="row tf-wrap-content">
                            <div class="<?php echo esc_attr( $main_class ) ?> content-wrap tf-content-wrap">
                                <div class="featured-post"><?php the_post_thumbnail( 'full' ); ?></div>
                                <div class="tf-single-course-main-content">
                                    <ul class="nav nav-tabs tf-single-course-content" id="single-course-tab"
                                        role="tablist">
                                        <li class="nav-item overview" role="presentation">
                                            <a class="nav-link active" id="overview-tab"
                                               data-bs-toggle="tab"
                                               href="#overview-tab-pane" role="tab"
                                               aria-controls="overview-tab-pane"
                                               aria-selected="true"><?php esc_html_e( 'Overview', 'themesflat' ) ?>
                                            </a>
                                        </li>
                                        <li class="nav-item curriculum" role="presentation">
                                            <a class="nav-link" id="curriculum-tab" data-bs-toggle="tab"
                                               href="#curriculum-tab-pane" role="tab"
                                               aria-controls="curriculum-tab-pane" aria-selected="false">
												<?php esc_html_e( 'Curriculum', 'themesflat' ) ?>
                                            </a>
                                        </li>
                                        <li class="nav-item" role="presentation">
                                            <a class="nav-link" id="instructor-tab" data-bs-toggle="tab"
                                               href="#instructor-tab-pane" role="tab"
                                               aria-controls="instructor-tab-pane" aria-selected="false">
												<?php esc_html_e( 'Instructor', 'themesflat' ) ?>
                                            </a>
                                        </li>
                                        <li class="nav-item" role="presentation">
                                            <a class="nav-link" id="reviews-tab" data-bs-toggle="tab"
                                               href="#reviews-tab-pane" role="tab"
                                               aria-controls="reviews-tab-pane" aria-selected="false">
												<?php esc_html_e( 'Reviews', 'themesflat' ) ?>
                                            </a>
                                        </li>
                                    </ul>
                                    <div class="tab-content" id="single-course-tab-content">
                                        <div class="tab-pane fade show active" id="overview-tab-pane"
                                             role="tabpanel" aria-labelledby="overview-tab" tabindex="0">
											<?php the_content(); ?>
                                        </div>
                                        <div class="tab-pane fade" id="curriculum-tab-pane" role="tabpanel"
                                             aria-labelledby="curriculum-tab" tabindex="0">
											<?php echo $curriculum ?>
                                        </div>
                                        <div class="tab-pane fade" id="instructor-tab-pane" role="tabpanel"
                                             aria-labelledby="instructor-tab" tabindex="0">
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="tf-instructor">
                                                        <div class="tf-instructor-image">
                                                            <img src="<?php echo esc_url( $url ) ?>"
                                                                 alt="<?php echo esc_attr( $name ) ?>">
                                                            <div class="image-hover">
																<?php if ( ! empty( $face ) ):
																	?>
                                                                    <a href="<?php echo esc_url( $face ) ?>"
                                                                       class="icon icon-facebook"><i
                                                                                class="fab fa-facebook-f"></i></a>
																<?php endif;
																if ( ! empty( $twitter ) ):
																	?>
                                                                    <a href="<?php echo esc_url( $twitter ) ?>"
                                                                       class="icon icon-twitter"><i
                                                                                class="fab fa-twitter"></i></a>
																<?php endif;
																if ( ! empty( $insta ) ):
																	?>
                                                                    <a href="<?php echo esc_url( $insta ) ?>"
                                                                       class="icon icon-instagram"><i
                                                                                class="fab fa-instagram"></i></a>
																<?php endif;
																if ( ! empty( $behance ) ):
																	?>
                                                                    <a href="<?php echo esc_url( $behance ) ?>"
                                                                       class="icon icon-behance"><i
                                                                                class="fab fa-behance"></i></a>
																<?php endif; ?>

                                                            </div>
                                                        </div>
                                                        <div class="tf-instructor-content">
                                                            <h3 class="tf-instructor-name"><?php echo esc_html( $name ) ?></h3>
                                                            <p class="tf-instructor-position"><?php echo esc_html( $position ) ?></p>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="tab-pane fade" id="reviews-tab-pane" role="tabpanel"
                                             aria-labelledby="reviews-tab" tabindex="0">
											<?php
											// If comments are open or we have at least one comment, load up the comment template
											if ( comments_open() || get_comments_number() ) :
												comments_template();
											endif;
											?>
                                        </div>
                                    </div>
									<?php if ( themesflat_get_opt( 'courses_show_post_navigator' ) == 1 ): ?>
                                        <!-- Navigation  -->
                                        <div class="container">
											<?php themesflat_post_navigation(); ?>
                                        </div>
									<?php endif; ?>
                                </div>
                                <!-- Related -->
								<?php
								if ( themesflat_get_opt( 'courses_show_related' ) == 1 ) { ?>

									<?php
									$grid_columns = themesflat_get_opt( 'courses_related_grid_columns' );
									$layout       = 'courses-grid';

									if ( get_query_var( 'paged' ) ) {
										$paged = get_query_var( 'paged' );
									} elseif ( get_query_var( 'page' ) ) {
										$paged = get_query_var( 'page' );
									} else {
										$paged = 1;
									}

									$terms    = get_the_terms( $post->ID, 'courses_category' );
									if ( $terms ) :
										$term_ids = wp_list_pluck( $terms, 'term_id' );
										$args = array(
											'post_type'           => 'courses',
											'posts_per_page'      => themesflat_get_opt( 'number_related_post_courses' ),
											'ignore_sticky_posts' => 1,
											'post__not_in'        => array( $post->ID )
										);
										if ( $term_ids ) {
											$args['tax_query'] = array(
												array(
													'taxonomy' => 'courses_category',
													'field'    => 'term_id',
													'terms'    => $term_ids,
													'operator' => 'IN'
												)
											);
										}

										if ( $layout != '' ) {
											$class[] = $layout;
										}
										if ( $grid_columns != '' ) {
											$class[] = 'column-' . $grid_columns;
										}
										$slick_options   = array(
											'slidesToShow' => intval( $grid_columns ),
											'arrows'        => true,
										);
										$tablet_settings = array(
											'slidesToShow' => 2,
											'arrows'        => false,
										);
										$mobile_settings = array(
											'slidesToShow' => 1,
											'arrows'        => false,
										);
										$responsive      = array(
											array(
												'breakpoint' => '768',
												'settings'   => $tablet_settings
											),
											array(
												'breakpoint' => '576',
												'settings'   => $mobile_settings
											)
										);

										$slick_options['responsive'] = $responsive;

										$query = new WP_Query( $args );
										if ( $query->have_posts() ) :
											?>
                                            <div class="related-post related-posts-box">
                                                <div class="box-wrapper">
                                                    <h3 class="box-title"><?php esc_html_e( 'Related Course', 'themesflat' ) ?></h3>
                                                    <div class="themesflat-courses-taxonomy">
                                                        <div class="<?php echo esc_attr( implode( ' ', $class ) ) ?> wrap-courses-post has-carousel"
                                                             data-slick-options="<?php echo esc_attr( json_encode( $slick_options ) ) ?>">
															<?php
															while ( $query->have_posts() ) : $query->the_post();
																$id                = $post->ID;
																$price             = get_post_meta( $id, 'tf_course_price', true );
																$theory_session    = get_post_meta( $id, 'tf_course_theory_session', true );
																$practical_session = get_post_meta( $id, 'tf_course_practical_session', true );
																?>
                                                                <div class="item">
                                                                    <div class="courses-post courses-post-style2 courses-post-<?php the_ID(); ?> <?php if ( has_post_thumbnail() ) {
																		echo 'has-thumbnail';
																	} ?>">
																		<?php if ( has_post_thumbnail() ): ?>
                                                                            <div class="featured-post">
																				<?php
																				themesflat_render_thumbnail_markup( array(
																					'image_size'  => '370x270',
																					'image_mode'  => 'background',
																					'placeholder' => ''
																				) );
																				?>
                                                                            </div>
																		<?php endif; ?>
                                                                        <div class="content-wrap">
                                                                            <div class="price-wrap">
                                                                                <sup><?php esc_html_e( '$', 'themesflat-elementor' ) ?></sup>
                                                                                <span class="price"><?php echo esc_html( $price ) ?></span><?php esc_html_e( '/Person', 'themesflat-elementor' ) ?>
                                                                            </div>
                                                                            <div class="content">
                                                                                <h2 class="title">
                                                                                    <a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a>
                                                                                </h2>
                                                                                <div class="tf-course-addition-informartion">
																					<?php $url = wp_get_attachment_url( $id_image );
																					if ( ! empty( $url ) ):
																						?>
                                                                                        <div class="instructor-image">
	                                                                                        <?php themesflat_render_thumbnail_markup( array(
		                                                                                        'image_id'    => $id_image,
		                                                                                        'image_size'  => '200x200',
		                                                                                        'image_mode'  => 'background',
		                                                                                        'placeholder' => ''
	                                                                                        ) ); ?>
                                                                                        </div>
																					<?php endif; ?>
                                                                                    <div class="instructor-content">
                                                                                        <p class="instructor-name"><?php echo esc_html( $name ) ?></p>
                                                                                        <p class="instructor-theory"><?php echo esc_html( $theory_session ) ?></p>
                                                                                    </div>
                                                                                </div>
                                                                            </div>
                                                                            <a href="<?php echo get_the_permalink(); ?>"
                                                                               class="courses-view-more">
                                                                                <span class="text"><?php esc_html_e( 'Start Now', 'themesflat-elementor' ) ?></span>
                                                                                <span class="icon"><i
                                                                                            class="fal fa-long-arrow-right"></i></span>
                                                                            </a>
                                                                        </div>
                                                                    </div>
                                                                </div>
															<?php
															endwhile;
															?>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
										<?php
										endif;
										wp_reset_postdata();
									endif; ?>
								<?php } ?>
                            </div>
							<?php
							if ( themesflat_get_opt( 'courses_single_layout' ) == 'sidebar-left' || themesflat_get_opt( 'courses_single_layout' ) == 'sidebar-right' ) :
								get_sidebar();
							endif;
							?>
                        </div>

					<?php endwhile; // end of the loop. ?>
                </div><!-- ./entry-content -->
            </main><!-- #main -->
        </div><!-- #primary -->
    </div>
</div>


<?php get_footer(); ?>


