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

get_header(); ?>
<main id="content" class="middle-align">
   <?php if( get_option('one_login_business_hide_show', false) !== 'off'){ ?>
    <?php $one_login_business_slider_count = get_theme_mod('one_login_business_slider_count'); ?>
    <section id="slider1">
      <div id="carouselExampleAutoplaying" class="carousel slide" data-bs-ride="carousel">
        <?php $one_login_business_pages = array();
          for ( $count = 1; $count <= $one_login_business_slider_count; $count++ ) {
            $mod = intval( get_theme_mod( 'one_login_business_slider_page' . $count ));
            if ( 'page-none-selected' != $mod ) {
              $one_login_business_pages[] = $mod;
            }
          }
          if( !empty($one_login_business_pages) ) :
            $args = array(
              'post_type' => 'page',
              'post__in' => $one_login_business_pages,
              'orderby' => 'post__in',
            );
            $query = new WP_Query( $args );
            if ( $query->have_posts() ) :
              $i = 1;
        ?>     
        <div class="carousel-inner" role="listbox">
          <?php  while ( $query->have_posts() ) : $query->the_post(); ?>
            <div <?php if($i == 1){echo 'class="carousel-item active"';} else{ echo 'class="carousel-item"';}?>>
              <?php if(has_post_thumbnail()){ ?>
                <img src="<?php the_post_thumbnail_url('full'); ?>"/>
              <?php }else{?>
                <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/slider1.jpg" alt="" />
              <?php } ?>
              <div class="carousel-caption">
                <div class="inner_carousel slider-inner">
                  <h2><?php the_title();?></h2>
                  <?php if( get_option('one_login_business_slider_excerpt_show_hide',false) != 'off'){ ?> 
                  <p class="slider-excerpt"><?php echo wp_trim_words(get_the_content(), get_theme_mod('one_login_business_slider_excerpt_count',20) );?></p>
                  <?php } ?>
                  <div class="more-btn">              
                    <a class="button" href="<?php the_permalink(); ?>"><?php echo esc_html(get_theme_mod('one_login_business_slider_read_more',__('READ MORE','one-login-business'))); ?><i class="fas fa-angle-right"></i></a>
                  </div>
                </div>
              </div>
            </div>
          <?php $i++; endwhile; 
          wp_reset_postdata();?>
        </div>
        <?php else : ?>
            <div class="no-postfound"></div>
          <?php endif;
        endif;?>
        <a class="carousel-control-prev" type="button" data-bs-target="#carouselExampleAutoplaying" data-bs-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"><i class="fas fa-angle-left"></i></span>
          </a>
          <a class="carousel-control-next" type="button" data-bs-target="#carouselExampleAutoplaying" data-bs-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"><i class="fas fa-angle-right"></i></span>
          </a>
      </div>   
      <div class="clearfix"></div>
    </section>
  <?php }?>
 <?php if( get_option('one_login_business_service_hide_show', false) !== 'off'){ ?>
  <?php if( get_theme_mod( 'one_login_business_our_services_title','' ) != ''|| get_theme_mod( 'one_login_business_category_setting','' ) != ''|| get_theme_mod( 'one_login_business_our_services_subtitle','' ) != '') { ?>
    <section id="our-services">
      <div class="container"> 
            <?php if( get_theme_mod('one_login_business_our_services_title') != ''){ ?>
              <h3><?php echo esc_html(get_theme_mod('one_login_business_our_services_title','')); ?></h3>
              <h5><?php echo esc_html(get_theme_mod('one_login_business_our_services_subtitle','')); ?></h5>
            <?php }?>
          <div class="row mt-4">
            <?php
            $catData1=  get_theme_mod('one_login_business_category_setting');
            $one_login_business_category_order = get_theme_mod('one_login_business_category_order_type','ascending');
            if($catData1){
              $one_login_business_args = array( 

              'category_name' => esc_html($catData1 ,'one-login-business'),

              'posts_per_page' => get_theme_mod('one_login_business_service_count'),

              'order' => 'ASC'

            );
            // Adjust ordering based on user selection
            if ($one_login_business_category_order == 'descending') {
              $one_login_business_args['order'] = 'DESC';
            } else if ($one_login_business_category_order == 'a-to-z') {
              $one_login_business_args['orderby'] = 'title';
              $one_login_business_args['order'] = 'ASC';
            } else if ($one_login_business_category_order == 'z-to-a') {
              $one_login_business_args['orderby'] = 'title';
              $one_login_business_args['order'] = 'DESC';
            }
            $page_query = new WP_Query($one_login_business_args);?>
              <?php while( $page_query->have_posts() ) : $page_query->the_post(); ?>  
              	<div class="col-lg-3 col-md-6 col-sm-6 mb-3">
  	                <div class="service-box">
                      <img src="<?php echo (the_post_thumbnail_url('full')); ?>"/>
                      <div class="service-content">
                        <a href="<?php the_permalink(); ?>"><h4><?php the_title();?></h4></a><hr>
                        <p><?php the_excerpt(); ?></p>
                    	</div>
  	                </div>   
                  </div>   
                <?php endwhile; 
              wp_reset_postdata();
            }?>
          </div>
        <div class="clearfix"></div>
      </div>
    </section>
  <?php }?>
<?php }?>
</main>
<?php get_footer(); ?>