<?php
/**
 * Template Name: Home Template
 */

get_header(); ?>

<main id="skip-content">
  <section id="top-slider">
    <?php if(get_theme_mod('online_tutor_top_slider_setting',true) != ''){ ?>
    <?php $online_tutor_slide_pages = array();
      for ( $online_tutor_count = 1; $online_tutor_count <= 3; $online_tutor_count++ ) {
        $online_tutor_mod = intval( get_theme_mod( 'online_tutor_top_slider_page' . $online_tutor_count ));
        if ( 'page-none-selected' != $online_tutor_mod ) {
          $online_tutor_slide_pages[] = $online_tutor_mod;
        }
      }
      if( !empty($online_tutor_slide_pages) ) :
        $online_tutor_args = array(
          'post_type' => 'page',
          'post__in' => $online_tutor_slide_pages,
          'orderby' => 'post__in'
        );
        $online_tutor_query = new WP_Query( $online_tutor_args );
        if ( $online_tutor_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="owl-carousel" role="listbox">
      <?php  while ( $online_tutor_query->have_posts() ) : $online_tutor_query->the_post(); ?>
        <div class="slider-box">
          <?php if(has_post_thumbnail()){
            the_post_thumbnail();
            } else{?>
            <img src="<?php echo esc_url(get_theme_file_uri()); ?>/assets/img/slider.png" alt="" />
          <?php } ?>
          <div class="slider-inner-box">
            <?php if(get_theme_mod('online_tutor_slider_title_setting',1) == 1){ ?>
                <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
              <?php }?>
              <?php if(get_theme_mod('online_tutor_slider_content_setting',1) == 1){ ?>
                <p class="post"><?php echo wp_trim_words( get_the_content(), esc_attr(get_theme_mod('online_tutor_slider_excerpt_length', 10)) ); ?></p>
              <?php }?>
              <?php if(get_theme_mod('online_tutor_slider_button_setting',1) == 1 && get_theme_mod('online_tutor_slider_button_text','Explore Courses') != ''){ ?>
                <div class="slider-box-btn mt-4">
                  <a href="<?php the_permalink(); ?>"><?php esc_html_e(get_theme_mod('online_tutor_slider_button_text','Explore Courses')); ?></a>
                </div>
              <?php }?>
          </div>
        </div>
      <?php $i++; endwhile;
      wp_reset_postdata();?>
    </div>
    <?php else : ?>
      <div class="no-postfound"></div>
    <?php endif;
    endif;?>
    <?php }?>
  </section>

  <?php if (get_theme_mod('online_tutor_search_on_off', true)) {?>

  <div class="container">
    <div class="searchbox">
      <h3><?php esc_html_e('Find A Tutor','coaching-classes'); ?></h3>
      <?php get_search_form(); ?>
    </div>
  </div>

<?php }?>

<?php if(get_theme_mod('online_tutor_other_project_setting') != ''){ ?>
  <section id="projects" class="py-5">
    <div class="container">
      <?php if(get_theme_mod('online_tutor_projects_title') != ''){ ?>
        <h2 class="text-center"><?php echo esc_html(get_theme_mod('online_tutor_projects_title')); ?></h2>
      <?php }?>
      <div class="row mt-5">
        <?php $online_tutor_other_project_section = array();
          $project_loop = get_theme_mod('online_tutor_project_loop');
          for ($i=1; $i <= $project_loop; $i++) {
            $online_tutor_mod = intval( get_theme_mod( 'online_tutor_other_project_section' .$i));
            if ( 'page-none-selected' != $online_tutor_mod ) {
              $online_tutor_other_project_section[] = $online_tutor_mod;
            }
          }
          if( !empty($online_tutor_other_project_section) ) :
          $online_tutor_args = array(
            'post_type' => 'post',
            'post__in' => $online_tutor_other_project_section,
            'orderby' => 'post__in'
          );
          $online_tutor_query = new WP_Query( $online_tutor_args );
          if ( $online_tutor_query->have_posts() ) :
            $i = 1;
        ?>
        <?php while ( $online_tutor_query->have_posts() ) : $online_tutor_query->the_post(); ?>
          <div class="col-lg-4 col-md-6">
            <div class="box mb-4">
              <?php if(has_post_thumbnail()){
                the_post_thumbnail();
                } else{?>
                <img src="<?php echo esc_url(get_theme_file_uri()); ?>/assets/img/lesson.png" alt="" class="w-100"/>
                <?php } ?>
              <div class="price-box text-right mr-3">
                <?php if(get_theme_mod('online_tutor_projects_price'.$i) != ''){ ?>
                  <h5><?php echo esc_html(get_theme_mod('online_tutor_projects_price'.$i)); ?></h5>
                <?php }?>
              </div>
              <div class="p-2">
                <h3><?php the_title(); ?></h3>
                <div class="readmore">
                  <a href="<?php the_permalink(); ?>"><?php esc_html_e('Enroll Now','coaching-classes'); ?></a>
                </div>
              </div>
              <div class="box-content">
                <h3 class="title"><?php the_title(); ?></h3>
                <p class="post"><?php echo wp_trim_words( get_the_content(), 30 ); ?></p>
                <div class="row">
                  <div class="col-lg-6 col-md-6 col-6 align-self-center">
                    <div class="readmore">
                      <a href="<?php the_permalink(); ?>"><?php esc_html_e('Enroll Now','coaching-classes'); ?></a>
                    </div>
                  </div>
                  <div class="col-lg-6 col-md-6 col-6 text-end align-self-center">
                    <?php if(get_theme_mod('online_tutor_projects_price'.$i) != ''){ ?>
                      <h5><?php echo esc_html(get_theme_mod('online_tutor_projects_price'.$i)); ?></h5>
                    <?php }?>
                  </div>
                </div>
              </div>
            </div>
          </div>
        <?php $i++; endwhile;
        wp_reset_postdata();?>
        <?php else : ?>
          <div class="no-postfound"></div>
        <?php endif;
        endif;?>
      </div>
    </div>
  </section>
  <?php }?>
  <section>
    <div class="container mt-5">
      <div class="heading-box text-center">
        <?php if(get_theme_mod('coaching_classes_contact_short_heading') != ''){ ?>
          <h4 class="m-0"><?php echo esc_html(get_theme_mod('coaching_classes_contact_short_heading')); ?></h4>
        <?php }?>
        <?php if(get_theme_mod('coaching_classes_contact_heading') != ''){ ?>
          <h3 class="mb-1"><?php echo esc_html(get_theme_mod('coaching_classes_contact_heading')); ?></h3>
        <?php }?>
        <?php if(get_theme_mod('coaching_classes_contact_text') != ''){ ?>
          <p class="mt-4"><?php echo esc_html(get_theme_mod('coaching_classes_contact_text')); ?></p>
        <?php }?>
      </div>
      <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-12 col-12 form-img">
          <img src="<?php echo esc_url(get_theme_mod('coaching_classes_contact_left_image')); ?>"/>
        </div>
        <div class="col-lg-6 col-md-6 col-sm-12 col-12 form-box">
          <?php if( get_theme_mod('coaching_classes_contact_shortcode') != ''){ ?>
              <?php echo do_shortcode(get_theme_mod( 'coaching_classes_contact_shortcode')); ?>
            <?php }?> 
        </div>
      </div>
    </div>
  </section>

  <section id="page-content">
    <div class="container">
      <div class="py-5">
        <?php
          if ( have_posts() ) :
            while ( have_posts() ) : the_post();
              the_content();
            endwhile;
          endif;
        ?>
      </div>
    </div>
  </section>
</main>

<?php get_footer(); ?>
