<?php
/**
 * Template Name: Custom Home Page
 */
get_header(); ?>

<main id="content">
   <?php if( get_option('senior_care_lite_slider_arrows', false) !== 'off'){ ?>
    <section id="slider">
      <div id="carouselExampleAutoplaying" class="carousel slide" data-bs-ride="carousel"> 
        <?php $senior_care_lite_slider_count = get_theme_mod('senior_care_lite_slider_count'); ?>
              <?php
                for ( $i = 1; $i <= $senior_care_lite_slider_count; $i++ ) {
            $mod =  get_theme_mod( 'senior_care_lite_post_setting' . $i );
            if ( 'page-none-selected' != $mod ) {
              $senior_care_lite_slide_post[] = $mod;
            }
          }
           if( !empty($senior_care_lite_slide_post) ) :
          $args = array(
            'post_type' =>array('post'),
            'post__in' => $senior_care_lite_slide_post,
            'ignore_sticky_posts'  => true, // Exclude sticky posts by default
          );

          // Check if specific posts are selected
          if (empty($senior_care_lite_slide_post) && is_sticky()) {
              $args['post__in'] = get_option('sticky_posts');
          }

          $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/slider.jpg" alt="" />
            <?php } ?>
            <div class="carousel-caption slider-inner">
              <?php if( get_theme_mod('senior_care_lite_slide_heading') != ''){ ?>
                <h3><?php echo esc_html(get_theme_mod('senior_care_lite_slide_heading','')); ?></h3>
              <?php }?>
              <h2 class="slider-title"><?php the_title();?></h2>
              <?php if( get_option('senior_care_lite_slider_excerpt_show_hide',false) != 'off'){ ?>
                <p class="slider-excerpt mb-0"><?php echo wp_trim_words(get_the_content(), get_theme_mod('senior_care_lite_slider_excerpt_count',20) );?></p>
              <?php } ?>
              <div class="home-btn my-4">
                <a class="py-md-3 px-md-4 py-2 px-3" href="<?php the_permalink(); ?>"><?php echo esc_html(get_theme_mod('senior_care_lite_slider_read_more',__('Donate Now','senior-care-lite'))); ?></a>
              </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-long-arrow-alt-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-long-arrow-alt-right"></i></span>
          </a>
      </div>
      <div class="clearfix"></div>
    </section>
  <?php }?>
  <?php if( get_option('senior_care_lite_hide_show_support', false) !== 'off'){ ?>
    <section id="support-info">
      <div class="container-md">
        <div class="support-info-box wow fadeInUpBig">
          <div class="row">
            <div class="col-lg-8 col-md-8 col-sm-9 align-self-center">
              <?php if( get_theme_mod('senior_care_lite_support_text') != '' ){ ?>
                <h3><?php echo esc_html(get_theme_mod('senior_care_lite_support_text','')); ?></h3>
              <?php }?>
              <?php if( get_theme_mod('senior_care_lite_support_phone_number') != '' ){ ?>
                <h5><?php echo esc_html(get_theme_mod('senior_care_lite_support_phone_number','')); ?></h5>
              <?php }?>
            </div>
            <div class="col-lg-4 col-md-4 col-sm-3 align-self-center">
              <?php if( get_theme_mod('senior_care_lite_support_btn_link') != '' || get_theme_mod('senior_care_lite_support_btn_text') != '' ){ ?>
                <div class="box-button text-center text-md-end">
                  <a href="<?php echo esc_url(get_theme_mod('senior_care_lite_support_btn_link','')); ?>"><?php echo esc_html(get_theme_mod('senior_care_lite_support_btn_text','')); ?></a>
                </div>
              <?php }?>
            </div>
          </div>
        </div>
      </div>
    </section>
  <?php }?>
  <?php if( get_option('senior_care_lite_mission_show_hide', false) !== 'off'){ ?>
    <section id="home-mission" class="py-5">
      <div class="container">
        <?php if( get_theme_mod('senior_care_lite_mission_main_title') != '' ){ ?>
          <h3 class="text-center"><?php echo esc_html(get_theme_mod('senior_care_lite_mission_main_title','')); ?></h3>
        <?php }?>
        <?php if( get_theme_mod('senior_care_lite_mission_short_title') != '' ){ ?>
          <p class="text-center width-box"><?php echo esc_html(get_theme_mod('senior_care_lite_mission_short_title','')); ?></p>
        <?php }?>
        
        <div class="row pt-4">
          <?php
            $project_category=  get_theme_mod('senior_care_lite_mission_category_setting');
            $senior_care_lite_mission_category_order = get_theme_mod('senior_care_lite_mission_category_order_type','descending');
            if($project_category){
              $senior_care_lite_args = array( 

              'category_name' => esc_html($project_category ,'senior-care-lite'),

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

              'order'          => 'DESC', // Default order

            );
              // Adjust ordering based on user selection
            if ($senior_care_lite_mission_category_order == 'ascending') {
              $senior_care_lite_args['order'] = 'ASC';
            } else if ($senior_care_lite_mission_category_order == 'a-to-z') {
              $senior_care_lite_args['orderby'] = 'title';
              $senior_care_lite_args['order'] = 'ASC';
            } else if ($senior_care_lite_mission_category_order == 'z-to-a') {
              $senior_care_lite_args['orderby'] = 'title';
              $senior_care_lite_args['order'] = 'DESC';
            }
            $page_query = new WP_Query($senior_care_lite_args);?>
              <?php while( $page_query->have_posts() ) : $page_query->the_post(); ?>
                <div class="col-lg-6 col-md-12 col-sm-12">
                  <div class="box mb-4">
                    <div class="row">
                      <div class="col-lg-5 col-md-5 align-self-center">
                        <div class="img-box wow zoomIn">
                          <?php if(has_post_thumbnail()){ ?>
                            <?php the_post_thumbnail(); ?>
                          <?php }else{?>
                            <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/image1.jpg" alt="" />
                          <?php } ?>
                        </div>
                      </div>
                      <div class="col-lg-7 col-md-7 align-self-center">
                        <div class="box-content p-3 text-center text-md-start">
                          <?php if( get_option('senior_care_lite_front_date',false) != 'off'){ ?>
                          <h6 class="mb-0"><?php the_time( get_option( 'date_format' ) ); ?></h6>
                           <?php }?>
                          <h4 class="mt-3"><?php the_title();?></h4>
                          <p><?php echo esc_html(wp_trim_words(get_the_content(),'20') );?></p>
                          <div class="box-button">
                            <a class="py-2 px-3" href="<?php the_permalink(); ?>"><?php esc_html_e('READ MORE','senior-care-lite');?></a>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              <?php endwhile;
            wp_reset_postdata();
          }?>
        </div>
      </div>
    </section>
  <?php }?>
  <section id="custom-page-content" <?php if ( have_posts() && trim( get_the_content() ) !== '' ) echo 'class="pt-3"'; ?>>
    <div class="container">
      <?php while ( have_posts() ) : the_post(); ?>
        <?php the_content(); ?>
      <?php endwhile; ?>
    </div>
  </section>
</main>

<?php get_footer(); ?>