<?php
/**
 * The Template Name: Home Page
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package Broker Consultants
 */

get_header(); ?>

<div id="content" >

  <?php
  $broker_consultants_hidepageboxes = get_theme_mod('broker_consultants_slider', true);

  if ($broker_consultants_hidepageboxes != '') { ?>
    <section id="slider-cat">
      <div class="container sliderbox">
        <div class="owl-carousel m-0">
            <?php
            $broker_consultants_catData = get_theme_mod('broker_consultants_slider_cat');
            if ($broker_consultants_catData) {
                $broker_consultants_page_query = new WP_Query(
                    array(
                        'category_name' => esc_attr(get_theme_mod('broker_consultants_slider_cat')),
                        'posts_per_page' => -1, 
                    )
                );
                while ($broker_consultants_page_query->have_posts()) : $broker_consultants_page_query->the_post(); ?>
                  <div class="row">
                      <div class="col-lg-5 col-md-5 col-12 align-self-center mb-md-4 mb-2">
                          <div class="text-content pe-lg-5">
                            <?php if(get_theme_mod('broker_consultants_slider_top_text') != ''){ ?>
                              <p class="slider-text mb-0"><?php echo esc_html(get_theme_mod('broker_consultants_slider_top_text')); ?></p>
                            <?php }?>
                            <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                            <div class="slide-btn mt-md-4">
                              <?php 
                              $broker_consultants_button_text = get_theme_mod('broker_consultants_button_text', 'GET STARTED');
                              $broker_consultants_button_link_slider = get_theme_mod('broker_consultants_button_link_slider', ''); 
                              if (empty($broker_consultants_button_link_slider)) {
                                  $broker_consultants_button_link_slider = get_permalink();
                              }
                              if ($broker_consultants_button_text || !empty($broker_consultants_button_link_slider)) { ?>
                                <?php if(get_theme_mod('broker_consultants_button_text', 'GET STARTED') != ''){ ?>
                                  <a href="<?php echo esc_url($broker_consultants_button_link_slider); ?>" class="button redmor">
                                    <?php echo esc_html($broker_consultants_button_text); ?>
                                      <span class="screen-reader-text"><?php echo esc_html($broker_consultants_button_text); ?></span>
                                  </a>
                                <?php } ?>
                              <?php } ?>
                            </div>
                          </div>
                      </div>
                      <div class="col-lg-1 col-md-1 col-12 align-self-center slider-bottom-text">
                        <div class="slider-users">
                          <?php if (get_theme_mod('broker_consultants_satisfied_number') != "") { ?>
                            <div class="row">
                              <div class="col-lg-4 col-md-3 col-3 align-self-center">
                                <i class="fas fa-heart"></i>
                              </div>
                              <div class="col-lg-8 col-md-9 col-9 align-self-center ps-3">
                                <p class="top-text m-0"><?php echo esc_html(get_theme_mod('broker_consultants_satisfied_number', '')); ?></p>
                                <p class="user-content m-0"><?php esc_html_e('Satisfied Users', 'broker-consultants'); ?></p>
                              </div>
                            </div>
                          <?php } ?> 
                        </div>
                    </div>
                    <div class="col-lg-6 col-md-6 col-12 align-self-center mb-4">
                      <div class="imagebox">
                        <?php if(has_post_thumbnail()){
                          the_post_thumbnail('full');
                          } else{?>
                          <img src="<?php echo esc_url(get_template_directory_uri()); ?>/images/slider.png" alt="<?php echo esc_attr( 'slider', 'broker-consultants'); ?>"/>
                        <?php } ?>
                      </div>
                    </div>
                  </div>
                <?php endwhile;
                wp_reset_postdata();
            }
            ?>
        </div>
      </div>
    </section>
  <?php } ?>

  <?php
    $broker_consultants_hidepageboxes = get_theme_mod('broker_consultants_disabled_pgboxes',true);
    $broker_consultants_blog_cat = get_theme_mod('broker_consultants_blog_cat');
    if( $broker_consultants_hidepageboxes && $broker_consultants_blog_cat){
  ?>
  <section id="blog" class="my-5">
    <div class="container">
      <div class="blog_bx mx-lg-5 px-lg-5 text-center">
        <?php if ( get_theme_mod('broker_consultants_headingtext1') != "") { ?>
          <h2 class="subhed mb-2"><?php echo esc_html(get_theme_mod('broker_consultants_headingtext1','broker-consultants')); ?></h2>
        <?php }?>
        <?php if ( get_theme_mod('broker_consultants_headingtext_para') != "") { ?>
          <h3 class="mb-3"><?php echo esc_html(get_theme_mod('broker_consultants_headingtext_para','broker-consultants')); ?></h3>
        <?php }?>
      </div>
      <div class="row">
    <?php
    if (get_theme_mod('broker_consultants_blog_cat')) {
        $broker_consultants_counter = 1; // Initialize the counter
        $broker_consultants_queryvar = new WP_Query(
            array(
                'cat'            => esc_attr(get_theme_mod('broker_consultants_blog_cat')),
                'posts_per_page' => esc_attr(get_theme_mod('broker_consultants_blog_count', 3)),
            )
        );

        while ($broker_consultants_queryvar->have_posts()) : $broker_consultants_queryvar->the_post(); ?>
            <div class="col-lg-4 col-md-6 service-box my-3">
                <?php
                $broker_consultants_image = get_the_post_thumbnail(null, 'full');
                if ($broker_consultants_image) {
                    echo '<div class="service-image">' . $broker_consultants_image;
                    echo '<div class="serial-number">' . sprintf('%02d', $broker_consultants_counter) . '</div>'; // Display formatted serial number
                    echo '</div>';
                }
                ?>
                <div class="blog-content <?php if (!$broker_consultants_image) echo ' no-thumbnail'; ?>">
                    <h4 class="mb-2"><a href="<?php the_permalink(); ?>"><?php echo get_the_title(); ?></a></h4>
                    <?php
                    $broker_consultants_trimexcerpt  = get_the_excerpt();
                    $broker_consultants_shortexcerpt = wp_trim_words($broker_consultants_trimexcerpt, $num_words = 12);
                    echo '<p class="serv-content">' . esc_html($broker_consultants_shortexcerpt) . '</p>';
                    ?>
                    <div class="service-btn mt-3">
                        <a class="text-decoration-none" href="<?php the_permalink(); ?>"><?php esc_html_e('View Service', 'broker-consultants'); ?></a>
                    </div>
                </div>
            </div>
            <?php
            $broker_consultants_counter++; // Increment the counter
        endwhile;
        wp_reset_postdata();
    }
    ?>
</div>

  </div>
  </section>
  <?php }?>

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