<?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 Robotics Services
 */

get_header(); ?>

<div id="content" >
    <?php
        $robotics_services_banner = get_theme_mod('robotics_services_banner', false);
        $robotics_services_banner_pageboxes = get_theme_mod('robotics_services_banner_pageboxes', false);
        $robotics_services_post_bg_image = file_get_contents(get_template_directory_uri() . '/images/post-bg.svg');

        if ($robotics_services_banner && $robotics_services_banner_pageboxes) { ?>
        <section id="banner-cat" class="position-relative">
            <img class="banner-bg" src="<?php echo esc_url(get_template_directory_uri()) ?>/images/banner-bg.png" alt="<?php echo esc_attr('Background Image', 'robotics-services'); ?>">
            <?php
            $robotics_services_querymed = new WP_Query(array(
                'page_id' => esc_attr($robotics_services_banner_pageboxes)
            ));
            while ($robotics_services_querymed->have_posts()) : $robotics_services_querymed->the_post(); ?>
                <div class="banner-outer-box position-absolute">
                    <div class="container">
                        <div class="row wow zoomIn" data-wow-delay=".4s">
                            <div class="col-xl-6 col-lg-6 col-md-7 col-12 align-self-center">
                                <div class="bannerbox">
                                    <div class="banner-innr-box text-lg-start text-md-start text-center">
                                        <?php if (get_theme_mod('robotics_services_banner_small_title') != "") { ?>
                                            <p class="bnr-sub-heading text-capitalize"><?php echo esc_html(get_theme_mod('robotics_services_banner_small_title')); ?></p>
                                        <?php } ?>
                                        <h1 class="mb-3 text-capitalize banner-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                                        <?php
                                            $robotics_services_trimexcerpt = get_the_excerpt();
                                            $robotics_services_shortexcerpt = wp_trim_words($robotics_services_trimexcerpt, 38);
                                            echo '<p class="banner-content mb-5">' . esc_html($robotics_services_shortexcerpt) . '</p>';
                                        ?>
                                        <div class="bannerbtn">
                                            <?php
                                                $robotics_services_button_text = get_theme_mod('robotics_services_button_text', 'Explore More');
                                                $robotics_services_button_link_banner = esc_url(get_theme_mod('robotics_services_button_link_banner', get_permalink()));
                                                if ($robotics_services_button_text || !empty($robotics_services_button_link_banner)) { ?>
                                                <?php if ($robotics_services_button_text != '') { ?>
                                                    <a href="<?php echo esc_url($robotics_services_button_link_banner); ?>" class="button text-capitalize">
                                                        <span class="btn-text"><?php echo esc_html($robotics_services_button_text); ?></span><i class="fa-solid fa-arrow-right"></i>
                                                        <span class="screen-reader-text"><?php echo esc_html($robotics_services_button_text); ?></span>
                                                    </a>
                                                <?php } ?>
                                            <?php } ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-xl-6 col-lg-6 col-md-5 col-12 align-self-center text-center banner-right-img position-relative">
                                <?php if (has_post_thumbnail()) { ?>
                                    <?php the_post_thumbnail('full bnr-inner-img position-absolute'); ?>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            <?php endwhile;
                wp_reset_postdata();
            ?>
        </section>
    <?php } ?>

    <!-- Case Study Section -->
    <?php
        $robotics_services_hide_case_study_section = get_theme_mod('robotics_services_disabled_case_study_section', false);
        $robotics_services_case_study_category = get_theme_mod('robotics_services_case_study_cat', '0');
        if ($robotics_services_hide_case_study_section){ ?>
        <section id="case-study-section" class="position-relative py-5">
            <div class="container">
                <?php if (get_theme_mod('robotics_services_case_study_text') != "" || get_theme_mod('robotics_services_case_study_title') != "") { ?>
                    <div class="row mb-5 pb-3 wow fadeInDown" data-wow-delay=".4s">
                        <div class="col-xl-9 col-lg-9 col-md-8 col-12 align-self-center">
                            <div class="blog-bx">
                                <p class="case-study-text text-capitalize mb-2"><?php echo esc_html(get_theme_mod('robotics_services_case_study_text')); ?></p>
                                <h2 class="case-study-title text-capitalize"><?php echo esc_html(get_theme_mod('robotics_services_case_study_title')); ?></h2>
                            </div> 
                        </div>
                        <div class="col-xl-3 col-lg-3 col-md-4 col-12 align-self-center text-end">
                            <?php if ( get_theme_mod('robotics_services_case_btn_text') != "") { ?> 
                                <div class="explore-btn">
                                    <a href="<?php echo esc_url(get_theme_mod ('robotics_services_case_btn_url')); ?>"><span class="case-btn text-capitalize"><?php echo esc_html(get_theme_mod ('robotics_services_case_btn_text')); ?></span><i class="fa-solid fa-arrow-right"></i></a>
                                </div>
                            <?php }?>
                        </div>
                    </div>
                <?php } ?>
                <div class="services-main-box">
                    <div class="row">
                        <?php
                            for ($robotics_services_i=1; $robotics_services_i <= 2; $robotics_services_i++) { 
                            $robotics_services_postData=  get_theme_mod('robotics_services_select_post'.$robotics_services_i);
                            if($robotics_services_postData){ ?>
                            <?php
                                $robotics_services_args = array(
                                    'p' => esc_html($robotics_services_postData ,'robotics-services'),
                                    'posts_per_page' => 2,
                                    'post_type' => 'post'
                                );
                                $robotics_services_query = new WP_Query( $robotics_services_args );
                                if ( $robotics_services_query->have_posts() ) :
                                while ( $robotics_services_query->have_posts() ) : $robotics_services_query->the_post(); ?>
                                <div class="col-xl-6 col-lg-6 col-md-6 col-12 align-self-center mb-5">
                                    <div class="services-box position-relative wow zoomIn">
                                        <div class="post-bg-img"><?php echo $robotics_services_post_bg_image; ?></div>
                                        <div class="case-content position-absolute">
                                            <div class="row">
                                                <div class="col-xl-5 col-lg-5 col-md-4 col-12 align-self-center">
                                                    <div class="service-img position-relative">
                                                        <?php if(has_post_thumbnail()){
                                                            the_post_thumbnail('full');
                                                            } else{?>
                                                            <img src="<?php echo esc_url(get_template_directory_uri()); ?>/images/post-img.png" alt="<?php echo esc_attr( 'post-image', 'robotics-services'); ?>"/>
                                                        <?php } ?>
                                                        <div class="case-img-overlay position-absolute"></div>
                                                    </div>
                                                </div>
                                                <div class="col-xl-7 col-lg-7 col-md-8 col-12 align-self-center">
                                                    <div class="services-main-content pe-lg-3 pe-md-3 pe-0">
                                                        <div class="services-inner-content">
                                                            <div class="services-content">
                                                                <div class="case-cat mb-2"><?php the_category(' > ', 'single'); ?></div>
                                                                <h5 class="post-head text-capitalize mb-0"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h5>
                                                                <p class="services-description mt-2 mb-3">
                                                                    <?php
                                                                    $robotics_services_excerpt = get_the_excerpt();
                                                                    $robotics_services_short_excerpt = wp_trim_words($robotics_services_excerpt, 25, '...');
                                                                    echo esc_html($robotics_services_short_excerpt);
                                                                    ?>
                                                                </p>
                                                                <a class="services-btn" href="<?php echo esc_url(get_permalink($post->ID)); ?>"><span class="service-btn-text"><?php echo esc_html__('Explore More', 'robotics-services') ?></span><i class="fa-solid fa-arrow-right"></i></a>
                                                            </div> 
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>  
                                </div> 
                            <?php endwhile;
                                wp_reset_postdata();
                            endif; ?>
                        <?php }}?>
                    </div>
                </div>
            </div>
        </section>
    <?php } ?>
</div>
<?php get_footer(); ?>