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

get_header();
?>

<main id="primary">

    <?php 
    $consultancy_services_main_slider_wrap = absint(get_theme_mod('consultancy_services_enable_slider', 0));
    if($consultancy_services_main_slider_wrap == 1): 
    ?>
        <section id="main-slider-wrap">
            <div class="owl-carousel">
                <?php for ($consultancy_services_main_i = 1; $consultancy_services_main_i <= 3; $consultancy_services_main_i++): ?>
                    <?php if ($consultancy_services_slider_image = get_theme_mod('consultancy_services_slider_image'.$consultancy_services_main_i)): ?>
                        <div class="main-slider-inner-box">
                            <img src="<?php echo esc_url($consultancy_services_slider_image); ?>" alt="<?php echo esc_attr(get_theme_mod('consultancy_services_slider_heading'.$consultancy_services_main_i)); ?>">
                            <div class="main-slider-content-box">
                                <div class="main-inner-text wow zoomIn" data-wow-duration="2s">
                                    <?php if ($consultancy_services_top_text = get_theme_mod('consultancy_services_slider_top_text' . $consultancy_services_main_i)): ?>
                                        <p class="slider-top"><?php echo esc_html($consultancy_services_top_text); ?></p>
                                    <?php endif; ?>
                                    <?php if ($consultancy_services_heading = get_theme_mod('consultancy_services_slider_heading' . $consultancy_services_main_i)): ?>
                                        <h1><?php echo esc_html($consultancy_services_heading); ?></h1>
                                    <?php endif; ?>
                                    <?php if ($consultancy_services_text = get_theme_mod('consultancy_services_slider_text'.$consultancy_services_main_i)): ?>
                                        <p class="slider-content"><?php echo esc_html($consultancy_services_text); ?></p>
                                    <?php endif; ?>
                                    <div class="main-slider-button">
                                        <?php if ( get_theme_mod('consultancy_services_slider_button1_link'.$consultancy_services_main_i) ||  get_theme_mod('consultancy_services_slider_button1_text'.$consultancy_services_main_i )) : ?><a class="btn-1" href="<?php echo esc_url( get_theme_mod('consultancy_services_slider_button1_link'.$consultancy_services_main_i) ); ?>"><i class="fas fa-arrow-right"></i><?php echo esc_html( get_theme_mod('consultancy_services_slider_button1_text'.$consultancy_services_main_i) ); ?></a><?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                <?php endfor; ?>
            </div>
            <!-- custom pagination -->
            <div class="custom-pagination">
                <span class="pagination-item active" data-slide="<?php echo esc_attr( 0 ); ?>">
                    <?php echo esc_html__( '1', 'consultancy-services' ); ?>
                </span>
                <span class="pagination-item" data-slide="<?php echo esc_attr( 1 ); ?>">
                    <?php echo esc_html__( '2', 'consultancy-services' ); ?>
                </span>
                <span class="pagination-item" data-slide="<?php echo esc_attr( 2 ); ?>">
                    <?php echo esc_html__( '3', 'consultancy-services' ); ?>
                </span>
            </div>
        </section>
    <?php endif; ?>

    <?php 
        $consultancy_services_servicesec = get_theme_mod('consultancy_services_service_show_hide', 1);
        if ($consultancy_services_servicesec == 1) : 
        ?>
        <section id="service-section">
          <div class="container"> 
            <div class="serv-head"> 
                <?php if (get_theme_mod('consultancy_services_section_short_title')) : ?>
                    <p class="short-title"><?php echo esc_html(get_theme_mod('consultancy_services_section_short_title')); ?></p>
                <?php endif; ?> 

                <?php if (get_theme_mod('consultancy_services_section_title')) : ?>
                    <h2 class="section-title"><?php echo esc_html(get_theme_mod('consultancy_services_section_title')); ?></h2>
                <?php endif; ?> 
            </div>
            <div class="owl-carousel owl-theme">
              <?php
              $consultancy_services_post_category = get_theme_mod('consultancy_services_offer_section_category','uncategorized');
              if ($consultancy_services_post_category) :
                $consultancy_services_category_id = term_exists($consultancy_services_post_category, '');
                if ($consultancy_services_category_id !== 0 && $consultancy_services_category_id !== null) :
                  $consultancy_services_posts_to_show = get_theme_mod('consultancy_services_posts_to_show', 4);
                  $consultancy_services_page_query = new WP_Query(array(
                    'category_name' => esc_attr($consultancy_services_post_category),
                    'posts_per_page' => $consultancy_services_posts_to_show,
                  ));

                  $consultancy_services_post_count = 0;
                  if ($consultancy_services_page_query->have_posts()) :
                    while ($consultancy_services_page_query->have_posts()) : $consultancy_services_page_query->the_post(); 
                      $consultancy_services_post_count++;
              ?>
                      <div class="item">
                        <div class="serv-box wow zoomIn" data-wow-duration="2s">
                            <div class="post-main-img">
                                <?php if ( has_post_thumbnail() ) : ?>
                                  <img src="<?php echo esc_url( get_the_post_thumbnail_url( null, 'full' ) ); ?>" alt="<?php the_title_attribute(); ?>" />
                                <?php else : ?>
                                  <img src="<?php echo esc_url( get_template_directory_uri() . '/revolution/assets/images/about1.png' ); ?>" alt="<?php the_title_attribute(); ?>" />
                                <?php endif; ?>
                                  <!-- Content and Social Icons Over Image -->
                                <div class="post-content">
                                    <h3>
                                      <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                    </h3>
                                    <div class="serv-tags">
                                      <?php
                                        // Get and display the post tags (limit to 2).
                                        $consultancy_services_post_tags = get_the_tags();
                                        if ( $consultancy_services_post_tags ) {
                                          $consultancy_services_tag_count = 0;
                                          echo '<div class="post-tags">';
                                          foreach ( $consultancy_services_post_tags as $tag ) {
                                            if ( $consultancy_services_tag_count < 2 ) {
                                              echo '<a href="' . esc_url( get_tag_link( $tag->term_id ) ) . '" class="tag-link">' . esc_html( $tag->name ) . '</a>';
                                              $consultancy_services_tag_count++;
                                            } else {
                                              break;
                                            }
                                          }
                                          echo '</div>'; // Close post-tags div
                                        }
                                      ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                      </div>
                    <?php endwhile; ?>
                    <?php wp_reset_postdata(); ?>
                  <?php else : ?>
                    <div class="no-postfound"></div>
                  <?php endif; ?>
                <?php endif; ?>
              <?php endif; ?>
            </div>
          </div>
        </section>
    <?php endif; ?>
</main>
<?php
get_footer();
?>