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

<!-- Start Banner 
    ============================================= -->
    <div class="banner-area content-less text-center">
        <div id="bootcarousel" class="carousel large-text text-light slide carousel-fade animate_text"
            data-ride="carousel">

            <!-- Wrapper for slides -->
            <div class="carousel-inner carousel-zoom">
                
            <?php if( have_rows('main_slider') ): ?>
                <?php $i=0; ?>
                <?php while( have_rows('main_slider') ): the_row();  $i++;?>
                
                <div class="carousel-item <?php echo($i==1?'active':'') ?>">
                    <div class="slider-thumb bg-fixed" style="background-image: url(<?php echo get_sub_field('image') ?>);"></div>
                    <div class="box-table">
                        <div class="box-cell shadow dark-hard">
                            <div class="container">
                                <div class="row">
                                    <div class="col-lg-12">
                                        <div class="content">
                                            <h3 data-animation="animated zoomInRight"><?php echo get_sub_field('sub_title') ?></h3>
                                            <h2 data-animation="animated fadeInUp"><?php echo get_sub_field('title') ?></h2>
                                            <div class="button animated fadeInUp">
                                                <a class="btn btn-gradient green circle effect btn-md" href="<?php echo get_sub_field('target_url') ?>"><?php echo get_sub_field('button_text') ?></a>
                                                <a class="popup-youtube relative video-play-button"
                                                    href="<?php echo get_sub_field('video_url') ?>">
                                                    <i class="fa fa-play"></i>
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php endwhile; ?>
            <?php endif; ?>

                
            </div>
            <!-- End Wrapper for slides -->

            <!-- Left and right controls -->
            <a class="left carousel-control shadow light" href="#bootcarousel" data-slide="prev">
                <i class="ti-angle-left"></i>
                <span class="sr-only">Previous</span>
            </a>
            <a class="right carousel-control shadow light" href="#bootcarousel" data-slide="next">
                <i class="ti-angle-right"></i>
                <span class="sr-only">Next</span>
            </a>

        </div>
    </div>
    <!-- End Banner -->

    <?php if( have_rows('content_section_with_image') ): ?>
    <?php while ( have_rows('content_section_with_image') ) : the_row(); ?>

        <?php if( get_row_layout() == 'content_section_01_with_image' ): ?>
        <!-- Star About Area
        ============================================= -->
        <div class="about-content-area single-thumb overflow-hidden inc-shape default-padding">
            <!-- Illustration -->
            <div class="illustration">
                <img src="<?php echo get_template_directory_uri() ?>/assets/img/shape/4.png" alt="Illustration">
            </div>
            <!-- Illustration -->
            <div class="container">
                <div class="row">

                    <div class="col-lg-6 info">
                        
                        <div class="content">
                            <h5><?php echo get_sub_field('section_sub_title') ?></h5>
                            
                            <?php if( have_rows('content_section') ): ?>
                                <?php while( have_rows('content_section') ): the_row(); ?>
                                <h2 class="area-title"><?php echo get_sub_field('main_title') ?></h2>
                                <p><?php echo get_sub_field('description') ?></p>
                                <?php endwhile; ?>
                            <?php endif; ?>
                            <a class="btn circle btn-theme border btn-md" href="<?php echo get_sub_field('target_url') ?>"><?php echo get_sub_field('button_text') ?></a>
                        </div>
                        

                        <ul class="achivement">
                        <?php if( have_rows('stat') ): ?>
                            <?php while( have_rows('stat') ): the_row(); ?>
                        
                            <li>
                                <div class="fun-fact">
                                    <div class="counter">
                                        <div class="timer" data-to="<?php echo get_sub_field('stat_value'); ?>" data-speed="5000"><?php echo get_sub_field('stat_value'); ?></div>
                                        <div class="operator">+</div>
                                    </div>
                                    <span class="medium"><?php echo get_sub_field('stat_title'); ?></span>
                                </div>
                            </li>

                            <?php endwhile; ?>
                        <?php endif; ?>


                        </ul>
                    </div>
                    <div class="col-lg-6">
                        <div class="thumb">
                            <img src="<?php echo get_sub_field('image') ?>" alt="Thumb">
                            <div class="experience">
                                <h2><strong>25+</strong> Years of experience</h2>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <!-- End About Area --> 
        <?php endif; ?>
    <?php endwhile; ?>
    <?php endif; ?>

      
    <!-- Start Services 
    ============================================= -->
    <div class="thumb-services-area half-bg bg-gradient-green default-padding bottom-less">
    <?php if( have_rows('section_description') ): ?>
        <?php while ( have_rows('section_description') ) : the_row(); ?>

        <?php if( get_row_layout() == 'section_description_01' ): ?>

        <div class="container">
            <div class="heading-left text-light">
                <div class="row">
                    <div class="col-lg-5">
                        <h1 class="text-invisible">
                            Products
                        </h1>
                        <h5><?php echo get_sub_field('section_sub_title'); ?></h5>
                        <h2><?php echo get_sub_field('section_title'); ?></h2>
                    </div>
                    <div class="col-lg-6 offset-lg-1 d-none" style="text-align: right;">
                        <a class="btn circle btn-md btn-theme effect" href="<?php echo site_url() ?>/products">View All Products<i
                                class="fas fa-angle-right"></i></a>
                    </div>
                </div>
            </div>
        </div>

        <?php endif; ?>

        <?php endwhile; ?>
        <?php endif; ?>

        <div class="services-content-box">
            <div class="container">
                <div class="services-items services-carousel owl-carousel owl-theme">
                <?php 
                // Fetch terms of the taxonomy 'project-category'
                $terms = get_terms( array(
                    'taxonomy' => 'project-category',
                    'hide_empty' => false,
                    'parent' => 0,
                ) );

                if ( !empty( $terms ) && !is_wp_error( $terms ) ) : 
                    foreach ( $terms as $term ) : 
                        // Get the term link and term meta (if available)
                        $term_link = get_term_link( $term );
                        // Optional: Add ACF fields for images or content if applicable
                        $term_image = get_field('category_image', $term); // If using ACF for image field
                ?>
                    <!-- Single Item -->
                    <div class="item">
                        <div class="thumb">
                            <img src="<?php echo $term_image ?>" alt="Thumb">
                        </div>
                        <div class="content">
                            <div class="icon">
                                <i class="flaticon-fertilizer"></i>
                            </div>
                            <div class="title">
                                <h5><a href="<?php echo esc_url( $term_link ); ?>"><?php echo esc_html( $term->name ); ?></a></h5>
                            </div>
                            <p><?php echo esc_html( $term->description ); ?></p>
                        </div>
                    </div>
                    <!-- End Single Item -->
                    <?php 
                    endforeach;
                endif;
                ?>
                    
                   
                </div>
            </div>
        </div>
    </div>
    <!-- End Services Area -->

    
<!-- Start Specialty 
    ============================================= -->
    <div class="specialty-area half-bg overflow-hidden" style="margin-top: 120px;">
        <div class="container-full">
        <?php if( have_rows('section_description') ): ?>
            <?php while ( have_rows('section_description') ) : the_row(); ?>
            <?php if( get_row_layout() == 'section_description_02' ): ?>
            <div class="specialty-items default-padding">
                <!-- Fixed BG -->
                <div class="fixed-bg bg-fixed shadow dark" style="background-image: url(<?php echo get_sub_field('section_image'); ?>);">

                </div>
                <!-- End Fixed BG -->
                <div class="row">
                    <div class="col-lg-12 info text-light">
                        <h2><?php echo get_sub_field('section_title'); ?></h2>
                    </div>
                    <div class="col-lg-12">
                        <div class="specialty-contents specialty-carousel owl-carousel owl-theme text-center">
                        <?php if( have_rows('section_box') ): ?>
                            <?php while( have_rows('section_box') ): the_row(); ?>
                            <div class="item">
                                <?php echo get_sub_field('icon'); ?>
                                <h5><?php echo get_sub_field('title'); ?></h5>
                                <p><?php echo get_sub_field('description'); ?></p>
                            </div>
                            <?php endwhile; ?>
                            <?php endif; ?>
                            
                        </div>
                    </div>
                </div>
            </div>
            <?php endif; ?>
            <?php endwhile; ?>
          <?php endif; ?>

        </div>
    </div>
    <!-- End Specialty Area -->
 


    <!-- Start Fun Factor Area
    ============================================= -->
    <div class="fun-factor-area default-padding">
        <!-- Illustration -->
        <div class="illustration wow fadeInDown">
            <img src="<?php echo get_template_directory_uri() ?>/assets/img/thumb/5.png" alt="Illustration">
        </div>
        <!-- End Illustration -->
        <div class="container">
            <div class="fun-fact-items text-center">
                <h2 class="text-invisible">Achivement</h2>
                <div class="row">
                    <div class="col-lg-3 col-md-6 item">
                        <div class="fun-fact">
                            <div class="timer" data-to="687" data-speed="5000">687</div>
                            <span class="medium">Lorem Ipsum</span>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6 item">
                        <div class="fun-fact">
                            <div class="timer" data-to="655" data-speed="5000">655</div>
                            <span class="medium">Lorem Ipsum</span>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6 item">
                        <div class="fun-fact">
                            <div class="timer" data-to="450" data-speed="5000">450</div>
                            <span class="medium">Lorem Ipsum</span>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6 item">
                        <div class="fun-fact">
                            <div class="timer" data-to="1200" data-speed="5000">1200</div>
                            <span class="medium">Lorem Ipsum</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- End Fun Factor Area -->

    <!-- Start Testimonials 
    ============================================= -->
    <div class="testimonials-area half-bg overflow-hidden text-light">
        <div class="container">
            <div class="tesimonials-content default-padding">
                <div class="row">
                <?php if( have_rows('section_description') ): ?>
                    <?php while ( have_rows('section_description') ) : the_row(); ?>
                    <?php if( get_row_layout() == 'section_description_03' ): ?>
                    <div class="col-lg-4 info">
                        <i class="flaticon-quotation"></i>
                        <h5><?php echo get_sub_field('section_sub_title'); ?></h5>
                        <h2><?php echo get_sub_field('section_title'); ?></h2>
                        <a class="btn circle btn-gradient green effect btn-md" href="#">View All <i
                                class="fas fa-angle-right"></i></a>
                    </div>
                    <?php endif; ?>
                    <?php endwhile; ?>
                <?php endif; ?>

                    <div class="col-lg-7 offset-lg-1 testimonials">
                        <div class="testimonial-items">
                            <div class="carousel slide" data-ride="carousel" id="testimonial-carousel">
                                <div class="carousel-inner">
                                <?php 
                                // Query custom post type 'testimonial'
                                $args = array(
                                    'post_type' => 'testimonial',
                                    'posts_per_page' => -1, // Change this number to limit the number of testimonials shown
                                );

                                $testimonial_query = new WP_Query($args); 
                                $navigation_html = '';
                                ?>
                                

                                <?php if ( $testimonial_query->have_posts() ) : ?>
                                    <?php while ( $testimonial_query->have_posts() ) : $testimonial_query->the_post(); ?>
                                    <?php $i = 0; // Counter to track the first item 
                                    
                                    if($i == 0){
                                        $active_item ='active';
                                    }
                                    ?>

                                    <div class="carousel-item <?php echo $active_item ?>">
                                        <p>
                                        <?php echo get_field('description'); ?>
                                        </p>
                                        <h4><?php the_title();  ?></h4>
                                        <span><?php the_field('designation'); ?></span>
                                    </div>
                                    <?php
                                    $navigation_html .= '<li data-target="#testimonial-carousel" data-slide-to="'.$i.'" class="'.$active_item.'">
                                        <img src="'. get_field('image').'" alt="Thumb">
                                    </li>';
                                    ?>
                                    <?php $i++; ?>
                                    <?php endwhile; ?>
                                <?php else : ?>
                                    <p>No testimonials found.</p>
                                <?php endif; ?>
                                <?php wp_reset_postdata(); ?>
                                                                    
                                    
                                </div>
                                <!-- End Carousel Content -->

                                <!-- Carousel Indicators -->
                                <ol class="carousel-indicators">
                                    <?php echo $navigation_html; ?>
                                   
                                   
                                </ol>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- End Testimonials Area -->


    <!-- Start Blog 
    ============================================= -->
    <div class="blog-area bg-gray default-padding bottom-less">
        <div class="container">
            <div class="row">
            <?php if( have_rows('section_description') ): ?>
                    <?php while ( have_rows('section_description') ) : the_row(); ?>
                    <?php if( get_row_layout() == 'section_description_04' ): ?>
                    <div class="col-lg-8 offset-lg-2">
                        <div class="site-heading text-center">
                            <h4><?php echo get_sub_field('section_sub_title'); ?></h4>
                            <h2><?php echo get_sub_field('section_title'); ?></h2>
                        </div>
                    </div>
                <?php endif; ?>
                    <?php endwhile; ?>
            <?php endif; ?>
            </div>
        </div>
        <div class="container">
            <div class="blog-items">
                <div class="row">
                <?php
                    // Query to get posts
                    $args = array(
                        'post_type' => 'post', // Change this to your custom post type if needed
                        'posts_per_page' => 3, // Number of posts to display
                        'orderby' => 'date', // Order by date
                        'order' => 'DESC' 
                    );

                    $query = new WP_Query($args); 
                    ?>

                    <?php if ( $query->have_posts() ) : ?>
                        <?php while ( $query->have_posts() ) : $query->the_post(); ?>
                            <!-- Single Item -->
                            <div class="single-item col-lg-4 col-md-6">
                                <div class="item">
                                    <div class="thumb">
                                        <?php if ( has_post_thumbnail() ) : ?>
                                            <img src="<?php the_post_thumbnail_url(); ?>" alt="<?php the_title_attribute(); ?>">
                                        <?php else : ?>
                                            <img src="<?php echo get_template_directory_uri(); ?>/assets/img/blog/default.jpg" alt="Default Thumbnail">
                                        <?php endif; ?>
                                        <div class="date"><?php echo get_the_date(); ?></div>
                                    </div>
                                    <div class="info">
                                        <h4>
                                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                        </h4>
                                        <p>
                                            <?php echo wp_trim_words( get_the_excerpt(), 20, '...' ); ?>
                                        </p>
                                        <div class="meta">
                                            <ul>
                                                <li><a href="#"><?php echo get_avatar( get_the_author_meta('ID'), 50 ); ?> <?php echo get_the_author_meta('display_name'); ?></a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- End Single Item -->
                        <?php endwhile; ?>
                    <?php else : ?>
                        <p>No posts found.</p>
                    <?php endif; ?>

                    <?php wp_reset_postdata(); ?>

                    
                    
                    
                </div>
            </div>
        </div>
    </div>
    <!-- End Blog Area -->
     <!-- Start Partner 
    ============================================= -->
    <div class="partner-area text-center default-padding bottom-less">
        <div class="container">
            <div class="partner-items">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="partner-carousel owl-carousel owl-theme">
                        <?php
                    // Query to get posts
                    $args = array(
                        'post_type' => 'client', // Change this to your custom post type if needed
                        'posts_per_page' => -1, // Number of posts to display
                        'orderby' => 'date', // Order by date
                        'order' => 'DESC' 
                    );

                    $query = new WP_Query($args); 
                    ?>
                    <?php if ( $query->have_posts() ) : ?>
                        <?php while ( $query->have_posts() ) : $query->the_post(); ?>

                            <img src="<?php the_post_thumbnail_url(); ?>" alt="Partner">
                            <?php endwhile; ?>
                    <?php else : ?>
                    <?php endif; ?>

                    <?php wp_reset_postdata(); ?>

                            
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- End Partner Area -->

<?php get_footer(); ?>