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

<!doctype html>
<html <?php language_attributes(); ?>>
<head>
  <meta charset="<?php bloginfo('charset'); ?>">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

<?php if ( function_exists( 'wp_body_open' ) ) { wp_body_open();} else { do_action( 'wp_body_open' ); } ?>

<?php if(get_theme_mod('adventure_tourism_preloader_hide','')){ ?>
    <div class="loading">
        <div class="dot"></div>
        <div class="dot"></div>
        <div class="dot"></div>
    </div>
<?php } ?>
<div id="page" class="site">
  <a class="skip-link screen-reader-text" href="#skip-content"><?php esc_html_e('Skip to content', 'adventure-tourism'); ?></a>
  <header id="masthead" class="site-header navbar-dark">
    <div class="socialmedia">
      <?php get_template_part('template-parts/topheader/mainheader'); ?>
    </div>
  </header>

<main id="skip-content">
  <?php if (get_theme_mod('adventure_tourism_slider_section_setting', false) != '') { ?>
    <section id="top-slider">
      <div class=" slider-right">
        <?php $adventure_tourism_slide_pages = array();
          for ( $adventure_tourism_count = 1; $adventure_tourism_count <= 3; $adventure_tourism_count++ ) {
            $adventure_tourism_mod = intval( get_theme_mod( 'adventure_tourism_top_slider_page' . $adventure_tourism_count ));
            if ( 'page-none-selected' != $adventure_tourism_mod ) {
              $adventure_tourism_slide_pages[] = $adventure_tourism_mod;
            }
          }
          if( !empty($adventure_tourism_slide_pages) ) :
            $adventure_tourism_args = array(
              'post_type' => 'page',
              'post__in' => $adventure_tourism_slide_pages,
              'orderby' => 'post__in'
            );
            $adventure_tourism_query = new WP_Query( $adventure_tourism_args );
            if ( $adventure_tourism_query->have_posts() ) :
              $i = 1;
        ?>
        <div id="combinedCarousel" class="owl-carousel" role="listbox">
          <?php  while ( $adventure_tourism_query->have_posts() ) : $adventure_tourism_query->the_post(); ?>
            <div class="slide-box row m-0">
              <div class="col-xl-5 col-lg-5 col-md-5 px-0">
                <div class="slider-content">
                  <div class="slider-inner-box">
                    <?php if(get_theme_mod('adventure_tourism_slider_short_heading') != ''){ ?>
                      <h4><?php echo esc_html(get_theme_mod('adventure_tourism_slider_short_heading')); ?></h4>
                    <?php }?>
                    <a href="<?php the_permalink(); ?>"><h3 class="m-0"><?php the_title(); ?></h3></a>
                    <p class="content mt-3"><?php echo esc_html( wp_trim_words( get_the_content(),15 )); ?></p>
                    <div class="slide-btn mt-4">
                      <a class="me-2" href="<?php the_permalink(); ?>"><?php esc_html_e('Know More Adventure','adventure-tourism'); ?></a>
                    </div>
                  </div>
                </div>
              </div>
              <div class="col-xl-7 col-lg-7 col-md-7 px-0">
                <div class="slider-image">
                  <?php if(has_post_thumbnail()){
                    the_post_thumbnail();
                  } else{?>
                    <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/img/slider.png" alt="" />
                  <?php } ?>
                </div>
              </div>
            </div>
          <?php $i++; endwhile;
           wp_reset_postdata();?>
          <?php else : ?>
          <div class="no-postfound"></div>
          <?php endif;
          endif;?>
        </div>
      </div>
      <div class="slider-header">
        <div class="row m-0">
          <div class="col-lg-10 col-md-10 col-2 align-self-center">
            <?php get_template_part('template-parts/navigation/nav'); ?>
          </div>
          <div class="col-lg-1 col-md-1 col-5 align-self-center text-end">
            <span class="cart_no">
              <?php if(class_exists('woocommerce')){ ?>
                <?php global $woocommerce; ?>
                <a class="cart-customlocation" href="<?php echo esc_url(wc_get_cart_url()); ?>" title="<?php esc_attr_e( 'shopping cart','adventure-tourism' ); ?>"><i class="fas fa-shopping-cart"></i></a>
              <?php }?>
            </span>
          </div>
          <div class="col-lg-1 col-md-1 col-5 p-0 text-end">
            <?php if( get_theme_mod('adventure_tourism_search_enable',false) != false){ ?>
              <span class="head-search">
                <span class="header-search-wrapper">
                  <span class="search-main">
                      <i class="fa fa-search"></i>
                  </span>
                  <div class="search-form-main clearfix">
                    <form method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
                      <input type="hidden" name="post_type" value="product"> <!-- Set post type to product for WooCommerce products -->
                      <label>
                          <input type="search" class="search-field form-control" placeholder="<?php esc_attr_e('Search for products...', 'adventure-tourism'); ?>" value="<?php echo get_search_query(); ?>" name="s">
                      </label>
                      <input type="submit" class="search-submit btn btn-primary mt-3" value="Search">
                    </form>
                  </div>
                </span>
              </span>
            <?php }?>
          </div>
        </div>
      </div>
    </section>
  <?php }?>

  <?php if (get_theme_mod('adventure_tourism_about_section_setting', false) != '') { ?>
    <section id="about-section" class="py-5">
      <div class="container">
        <div class="row">
          <div class="col-lg-3 col-md-3 align-self-center">
            <?php if (get_theme_mod('adventure_tourism_left_about_image') != '') {?>
              <img src="<?php echo esc_url(get_theme_mod('adventure_tourism_left_about_image'));?>"/>
            <?php } else {?>
              <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/img/slider.png"/>
            <?php }?>
          </div>
          <div class="col-lg-6 col-md-6 align-self-center">
            <div class="categorie-heading mb-5">
              <?php if(get_theme_mod('adventure_tourism_about_heading') != ''){ ?>
                <h3 class="main-heading mb-2"><?php echo esc_html(get_theme_mod('adventure_tourism_about_heading')); ?></h3>
              <?php }?>
              <?php if(get_theme_mod('adventure_tourism_about_content') != ''){ ?>
                <p class="main-heading"><?php echo esc_html(get_theme_mod('adventure_tourism_about_content')); ?></p>
              <?php }?>
            </div>
            <div class="feature-box">
              <div class="row">
                <?php for ($i=1; $i <= 4 ; $i++) { ?>
                  <div class="col-lg-6 col-md-6">
                    <div class="about-feature">
                      <?php if(get_theme_mod('adventure_tourism_featured_icon'.$i) != '') {?>
                        <i class="<?php echo esc_attr(get_theme_mod('adventure_tourism_featured_icon'.$i)); ?>"></i>
                      <?php }?>
                      <?php if(get_theme_mod('adventure_tourism_featured_title'.$i) != '') {?>
                        <h5><?php echo esc_html(get_theme_mod('adventure_tourism_featured_title'.$i)); ?></h5>
                      <?php }?>
                    </div>
                  </div>
                <?php }?>
              </div>
            </div>
            <?php if(get_theme_mod('adventure_tourism_about_btn_text') != '' || get_theme_mod('adventure_tourism_about_btn_url') != ''){?>
              <div class="about-btn text-center mt-4">
                <a href="<?php echo esc_url(get_theme_mod('adventure_tourism_about_btn_url')); ?>"><?php echo esc_html(get_theme_mod('adventure_tourism_about_btn_text')); ?></a>
              </div>
            <?php }?>
          </div>
          <div class="col-lg-3 col-md-3 align-self-center">
            <div class="right-img">
              <?php if (get_theme_mod('adventure_tourism_right_about_image') != '') {?>
                <img src="<?php echo esc_url(get_theme_mod('adventure_tourism_right_about_image'));?>"/>
              <?php } else {?>
                <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/img/slider.png"/>
              <?php }?>
              <?php if(get_theme_mod('adventure_tourism_discount_text') != ''){?>
                <p><?php echo esc_html(get_theme_mod('adventure_tourism_discount_text')); ?></p>
              <?php }?>
            </div>
          </div>
        </div>
        
      </div>
    </section>
  <?php }?>
  <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(); ?>