<?php
/**
 * The home content hook for Wacko theme.
 *
 * This is the template that displays home page contents of the theme
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package Wacko
 */

if ( ! function_exists( 'wacko_home_content' ) ) :

  function wacko_home_content(){

    $theme_options  = wacko_theme_options();
    ?>
        <?php
          do_action( 'wacko_banner_content' );
          do_action( 'wacko_services_content' );
          do_action( 'wacko_about_content' );
          do_action( 'wacko_testimonial_content' );
          do_action( 'wacko_info_content' );
          do_action( 'wacko_portfolio_content' );
          do_action( 'wacko_support_content' );
          do_action( 'wacko_cta_content' );
        ?>
      <?php
  }

endif;

add_action( 'wacko_action_home_content', 'wacko_home_content', 10 );


/**
 * For banner section
 */

if ( ! function_exists( 'wacko_banner_content_section' ) ) :

  function wacko_banner_content_section(){

    $theme_options  = wacko_theme_options();

    $enable_btn       = $theme_options['slider_btn_enable'];

    $enable_excerpt          = $theme_options['slider_excerpt_enable'];

    if( 'slider' === $theme_options['main_slider_type'] && ( 1 === $theme_options['slider_enable']) ){ 

      if(!empty( $theme_options['slider_cat'] )){

        $slider_args = array( 
                        'cat'             => absint( $theme_options['slider_cat'] ), 
                        'post_status'     => 'publish', 
                        'posts_per_page'  => 5,
                        'ignore_sticky_posts' => 1,
                      );

      } else{

        $slider_args = array( 'post_status' => 'publish', 'posts_per_page' => 5, 'ignore_sticky_posts' => 1 );

      }
       

      $slider_query = new WP_Query( $slider_args ); 

      if ( $slider_query->have_posts() ) {

    ?>

    <div class="banner">
      <div class="owl-carousel owl-theme">

        <?php 
          while ( $slider_query->have_posts() ) : $slider_query->the_post();

          $image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' ); ?>

          <?php if ( !empty( $image_url ) ) { ?>
            <div class="item">
          <?php } else { ?>
            <div class="item slider-bg-img">
          <?php } ?>
          <figure>
            <?php if ( !empty( $image_url ) ) { ?>
              <img src="<?php echo esc_url($image_url[0]); ?>">
            <?php } ?>
            <div class="overlay">
            </div><!--ovlerlay-->
          </figure>
          <div class="container">
            <div class="banner-text banner-caption">       
              <h2> <?php the_title(); ?> </h2>

              <?php if( 1 == $enable_excerpt ){ ?>

              <div class="entry-content">
                <?php the_excerpt(); ?>    
              </div><!--banner-caption-->

              <?php } ?>

              <?php if( 1 == $enable_btn ){ ?>
              <div class="btn btn-business">
                <a href="<?php the_permalink(); ?>"> <?php echo esc_html__( 'Read More', 'wacko' ) ?> </a>
              </div>
              <?php } ?>

            </div><!--caption -->
          </div><!--container-->
        </div><!--item-->

      <?php endwhile; ?>


      </div><!--owl-carousel-->
    </div><!--banner-->

    <?php
    wp_reset_postdata(); 
      } else {
        //do_action( 'wacko_page_header' );
      }

    } elseif( 'banner-image' === $theme_options['main_slider_type'] && ( 1 === $theme_options['slider_enable']) ) { 

      $banner_args = array( 
                        'p'             => absint( $theme_options['banner_image'] ),
                        'post_status'     => 'publish', 
                        'posts_per_page'  => 1,
                        'ignore_sticky_posts' => 1,
                      );

      if(empty( $banner_args )) {

        $banner_args = array( 'post_status' => 'publish', 'posts_per_page' => 1, 'ignore_sticky_posts' => 1 );

      }
       

      $banner_query = new WP_Query( $banner_args ); 

      if ( $banner_query->have_posts() ) {


    while ( $banner_query->have_posts() ) : $banner_query->the_post(); 

          $image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' ); ?>

          <?php if ( !empty( $image_url ) ) { ?>
            <div class="banner banner-img">
          <?php } else { ?>
            <div class="banner slider-bg-img">
          <?php } ?>


      <figure>
        <?php if ( !empty( $image_url ) ) { ?>
        <img src="<?php echo esc_url($image_url[0]); ?>">
        <?php } ?>
            <div class="overlay">
            </div><!--ovlerlay -->
          </figure>
          <div class="container">
            <div class="banner-text banner-caption">       
             <h2> <?php the_title(); ?> </h2>
             
             <?php if( 1 == $enable_excerpt ){ ?>

              <div class="entry-content">
                <?php the_excerpt(); ?> 
              </div><!--banner-caption-->

              <?php } ?>

            <?php if( 1 == $enable_btn ){ ?>
              <div class="btn btn-business">
                <a href="<?php the_permalink(); ?>"> <?php echo esc_html__( 'Read More', 'wacko' ) ?> </a>
              </div>
            <?php } ?>


          </div><!--caption -->
        </div><!--container-->  
    </div><!--banner-->

    <?php 
          endwhile;
        wp_reset_postdata(); 
      } else { ?>

        <div class="banner slider-bg-img">

      <figure>
            <div class="overlay">
            </div><!--ovlerlay -->
          </figure>
          <div class="container">
            <div class="banner-text banner-caption">       
            <h2> <?php echo esc_html( 'Invalid Post ID, Please insert the valid Post ID', 'wacko' ); ?> </h2>
             
          </div><!--caption -->
        </div><!--container-->  
    </div><!--banner-->

    <?php
        //do_action( 'wacko_page_header' );
      }
    } else {

      //do_action( 'wacko_page_header' );

    }

  }

endif;

add_action( 'wacko_banner_content', 'wacko_banner_content_section', 10 );


/**
 * For services section
 */

if ( ! function_exists( 'wacko_services_content_section' ) ) :

  function wacko_services_content_section(){

    $theme_options  = wacko_theme_options();

    $our_services   = $theme_options['our_services'];

    if( !empty( $our_services ) ){

    ?>

    <div class="features">
      <div class="container">
        <h3><span class="text-center"> 
          <?php echo esc_html(get_the_category_by_ID( absint( $our_services ) )); ?>
        </span></h3>

        <p>
          <?php echo wp_kses_post(category_description( absint( $our_services ) )); ?>
        </p>

        <?php
          $services_args = array( 
                'cat'             => absint( $our_services ), 
                'post_status'     => 'publish', 
                'posts_per_page'  => 3,
              );
          
          $services_query = new WP_Query( $services_args ); 

          if ( $services_query->have_posts() ) :
        ?>

        <div class="row">
        
        <?php while ( $services_query->have_posts() ) : $services_query->the_post();

          $service_img = wp_get_attachment_image_src( get_post_thumbnail_id(), 'wacko-feautres' );
         ?>


          <div class="col-xs-12 col-sm-4 col-md-4 content-features">
            <?php if(!empty( $service_img )) { ?>
            <figure>
              <img src="<?php echo esc_url($service_img[0]); ?>">
            </figure>
            <?php } ?>
            <h4> <?php the_title(); ?> </h4>
            <p>
              <?php the_content() ?>
            </p>
          </div><!--content-features-->

          <?php 
            endwhile;
          ?>

          <div class="clearfix"></div>

        </div><!--row--> 

        <?php
            wp_reset_postdata(); 
          endif;
        ?>

      </div><!--container-->
    </div><!--features-->

    <?php
      }

  }

endif;

add_action( 'wacko_services_content', 'wacko_services_content_section', 10 );


/**
 * For about section
 */

if ( ! function_exists( 'wacko_about_content_section' ) ) :

  function wacko_about_content_section(){

    $theme_options  = wacko_theme_options();

    $about_us         = $theme_options['about_us'];

    if( !empty( $about_us )){

      $about_args = array( 
        'page_id'         => absint( $about_us ), 
        'post_status'     => 'publish',
      );

      $about_query = new WP_Query( $about_args ); 

      if ( $about_query->have_posts() ) :

         while ( $about_query->have_posts() ) : $about_query->the_post();

    ?>

    <div class="template-responsive">
      <div class="container">
        <h3><span class="text-center"> <?php the_title() ?> </span></h3>
          <div class="row">
          <?php if ( has_post_thumbnail() ) {  ?>
            <div class="col-xs-12 col-sm-6 col-md-6 content-res-templates">
              <figure>
                <?php 
                  if ( has_post_thumbnail() ) { 
                    the_post_thumbnail( 'full' ); 
                  } ?>
              </figure>
            </div><!--content-res-templates-->

            <div class="col-xs-12 col-sm-6 col-md-6 content-res-templates">

            <?php } else { ?>

            <div class="col-xs-12 col-sm-12 col-md-12 content-res-templates">
              
            <?php } ?>

              <?php the_content(); ?>
            </div>
          </div><!--content-res-templates-->
        </div><!--row-->
      </div><!--container-->
    </div><!--template-responsive-->

    <?php
        endwhile;

        wp_reset_postdata();

        endif;
      }

  }

endif;

add_action( 'wacko_about_content', 'wacko_about_content_section', 10 );

/**
 * For testimonial section
 */

if ( ! function_exists( 'wacko_testimonial_content_section' ) ) :

  function wacko_testimonial_content_section(){

    $theme_options  = wacko_theme_options();

    $testimonial   = $theme_options['wacko_testi'];

    if( !empty( $testimonial ) ){

    ?>

    <div id="testimonial" class="testimonial">
      <div class="container">
        <div class="test-header text-center">
          <h3><span class="text-center"> <?php echo esc_html(get_the_category_by_ID( absint( $testimonial ) )); ?> </span></h3>

          <p>
            <?php echo wp_kses_post(category_description( absint( $testimonial ) )); ?>
          </p>

        </div>


        <?php
          $testimonial_args = array( 
                'cat'             => absint( $testimonial ), 
                'post_status'     => 'publish', 
                'posts_per_page'  => 3,
              );
          
          $testimonial_query = new WP_Query( $testimonial_args ); 

          if ( $testimonial_query->have_posts() ) :
        ?>

        <div class= "owl-carousel owl-theme">

        <?php while ( $testimonial_query->have_posts() ) : $testimonial_query->the_post();

          $testi_img = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
        ?>
          
          <div class="item">
            <div class="block-testimonial">

              <?php the_content( ); 

              if(!empty( $testi_img )) {
              ?>

              <figure>
                <img src="<?php echo esc_url($testi_img[0]); ?>">
              </figure>
              <?php } ?>
              <label> <?php the_title(); ?> </label>
            </div><!--block-testimonial-->
          </div><!--item-->

        <?php 
          endwhile;
        ?>


        </div><!--owl-carousel-1-->

        <?php
            wp_reset_postdata(); 
          endif;
        ?>

      </div><!--container-->
    </div><!--testimonial-->

    <?php

  }

  }

endif;

add_action( 'wacko_testimonial_content', 'wacko_testimonial_content_section', 10 );


/**
 * For info section
 */

if ( ! function_exists( 'wacko_info_content_section' ) ) :

  function wacko_info_content_section(){

    $theme_options  = wacko_theme_options();

    $information         = $theme_options['info_sec'];

    if( !empty( $information )){

      $info_args = array( 
        'page_id'         => absint( $information ), 
        'post_status'     => 'publish',
      );

      $info_query = new WP_Query( $info_args ); 

      if ( $info_query->have_posts() ) :

         while ( $info_query->have_posts() ) : $info_query->the_post();

       $info_img = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );

    ?>

    <div id="details" style="background-image: url(<?php echo esc_url($info_img[0]); ?>); background-repeat: no-repeat; background-size: cover; width: 100%;">
      <div class="container">
        <div class="content-details">
          <h2><span> <?php the_title(); ?> </span></h2>
        </div><!--content-details-->
        <?php the_excerpt(); ?>
        <a class="sec-detial" href="<?php the_permalink(); ?>"> <?php echo esc_html__( 'Learn More', 'wacko' ); ?> </a>

      </div><!--ontainer-->
      <div class="overlay">
      </div><!--overlay-2-->
    </div><!--details-->

    <?php

     endwhile;

        wp_reset_postdata();
      
      endif;

      }

  }

endif;

add_action( 'wacko_info_content', 'wacko_info_content_section', 10 );


/**
 * For portfolio section
 */

if ( ! function_exists( 'wacko_portfolio_content_section' ) ) :

  function wacko_portfolio_content_section(){

    $theme_options  = wacko_theme_options();

    $our_project   = $theme_options['our_project'];

    if( !empty( $our_project ) ){

    ?>

    <div class="portfolio text-center">
      <div class="container">
        <h3><span class="text-center">
            <?php echo esc_html(get_the_category_by_ID( absint( $our_project ) )); ?>
        </span></h3>
        <p>
          <?php echo wp_kses_post(category_description( absint( $our_project ) )); ?>
        </p>

        <?php
          $project_args = array( 
                'cat'             => absint( $our_project ), 
                'post_status'     => 'publish', 
                'posts_per_page'  => 6,
              );
          
          $project_query = new WP_Query( $project_args ); 

          if ( $project_query->have_posts() ) :
        ?>


        <div class="row portfolio-list">

        <?php while ( $project_query->have_posts() ) : $project_query->the_post();

        ?>


          <?php if ( has_post_thumbnail() ) { ?>
            <div class="col-xs-12 col-sm-4 col-md-4 list-work">
          <?php } else { ?>
            <div class="col-xs-12 col-sm-4 col-md-4 list-work work-bg-img">
          <?php } ?>
            <a href="<?php the_permalink(); ?>"> 
              <figure>
                  <?php 
                  if ( has_post_thumbnail() ) { 
                    the_post_thumbnail( 'wacko-project' ); 
                  } ?>
                <?php if ( !has_post_thumbnail() ) { ?>
                <div class="overlay">
                </div><!--overlay-->

                <figcaption>
                  <h3> <?php the_title(); ?> </h3>
                </figcaption> 
                <?php } ?>
                
                <div class="port-text">
                  <i class="fa fa-chain"></i>
                  <h3> <?php the_title(); ?> </h3>
                </div>  
              </figure>
            </a>
          </div><!--list-work-->

          <?php endwhile; ?>



        </div><!--row-->

        <?php
            wp_reset_postdata(); 
          endif;
        ?>


      </div><!--container-->

    </div><!--portfolio-->

    <?php
    }

  }

endif;

add_action( 'wacko_portfolio_content', 'wacko_portfolio_content_section', 10 );


/**
 * For support section
 */

if ( ! function_exists( 'wacko_support_content_section' ) ) :

  function wacko_support_content_section(){

    $theme_options  = wacko_theme_options();

    $support         = $theme_options['our_support'];

    if( !empty( $support )){

      $support_args = array( 
        'page_id'         => absint( $support ), 
        'post_status'     => 'publish',
      );

      $support_query = new WP_Query( $support_args ); 

      if ( $support_query->have_posts() ) :

         while ( $support_query->have_posts() ) : $support_query->the_post();

    ?>

    <div class="support text-center">
      <div class="container">
        <i class="fa fa-support"></i>
        <h3><span class="text-center"> <?php the_title() ?> </span></h3>
          <?php the_content(); ?>
        </div><!--container-->

      </div><!--support-->

   
    <?php
    endwhile;

        wp_reset_postdata();

        endif;
  }

  }

endif;

add_action( 'wacko_support_content', 'wacko_support_content_section', 10 );


/**
 * For call to action section
 */

if ( ! function_exists( 'wacko_cta_content_section' ) ) :

  function wacko_cta_content_section(){

    $theme_options  = wacko_theme_options();

    $wacko_cta         = $theme_options['wacko_cta'];

    if( !empty( $wacko_cta )){

      $cta_args = array( 
        'page_id'         => absint( $wacko_cta ), 
        'post_status'     => 'publish',
      );

      $cta_query = new WP_Query( $cta_args ); 

      if ( $cta_query->have_posts() ) :

        while ( $cta_query->have_posts() ) : $cta_query->the_post();

        $cta_image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );

    ?>

    <div id="download" style="background-image: url(<?php echo esc_url($cta_image[0]); ?>); background-repeat: no-repeat; background-size: cover; width: 100%;">
      <div class="overlay">
      </div>
      <div class="container">
        <div class="row">
          <div class="col-xs-12 col-sm-8 col-md-8 content-download">
            <h3> <?php the_title() ?> </h3>

            <?php the_excerpt(); ?>
        
          </div>

          <div class="col-xs-12 col-sm-4 col-md-4 content-download">
            <a class="sec-detial" href="<?php the_permalink(); ?>">
              <?php echo esc_html__( 'Learn More', 'wacko' ) ?>
            </a>
          </div>

        </div><!--row-->
      </div><!--container-->
    </div><!--download-->

   
    <?php
    endwhile;

    wp_reset_postdata();

  endif;
  }

  }

endif;

add_action( 'wacko_cta_content', 'wacko_cta_content_section', 10 );
