<?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 Roofing Installation
 */

get_header(); ?>

<div id="content" >
    <?php
        $roofing_installation_banner = get_theme_mod('roofing_installation_banner', false);
        $roofing_installation_banner_pageboxes = get_theme_mod('roofing_installation_banner_pageboxes', false);

        if ($roofing_installation_banner && $roofing_installation_banner_pageboxes) { ?>
        <section id="banner-cat" class="position-relative wow fadeIn" data-wow-delay=".2s">
            <?php
            $roofing_installation_querymed = new WP_Query(array(
                'page_id' => esc_attr($roofing_installation_banner_pageboxes)
            ));
            while ($roofing_installation_querymed->have_posts()) : $roofing_installation_querymed->the_post(); ?>
                <div class="banner-bg-img position-relative">
                    <?php if (has_post_thumbnail()) { ?>
                        <?php the_post_thumbnail('full bnr-inner-img'); ?>
                    <?php } ?>
                    <div class="banner-overlay position-absolute"></div>
                </div>
                <div class="bannerbox text-center position-absolute">
                    <div class="container">
                        <div class="banner-innr-box wow fadeInDown" data-wow-delay=".4s">
                            <h1 class="mb-4 text-capitalize banner-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                            <?php
                                $roofing_installation_trimexcerpt = get_the_excerpt();
                                $roofing_installation_shortexcerpt = wp_trim_words($roofing_installation_trimexcerpt, 38);
                                echo '<p class="banner-content mb-5">' . esc_html($roofing_installation_shortexcerpt) . '</p>';
                            ?>
                            <div class="bannerbtn">
                                <?php
                                    $roofing_installation_button_text = get_theme_mod('roofing_installation_button_text', 'Get a Free Roof Inspection');
                                    $roofing_installation_button_link_banner = esc_url(get_theme_mod('roofing_installation_button_link_banner', get_permalink()));
                                    if ($roofing_installation_button_text || !empty($roofing_installation_button_link_banner)) { ?>
                                    <?php if ($roofing_installation_button_text != '') { ?>
                                        <a href="<?php echo esc_url($roofing_installation_button_link_banner); ?>" class="button">
                                            <?php echo esc_html($roofing_installation_button_text); ?>
                                            <span class="screen-reader-text"><?php echo esc_html($roofing_installation_button_text); ?></span>
                                        </a>
                                    <?php } ?>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            <?php endwhile;
                wp_reset_postdata();
            ?>
        </section>
    <?php } ?>

    <!-- Services Section -->
    <?php
        $roofing_installation_hide_services_section = get_theme_mod('roofing_installation_disabled_services_section', false);
        if ($roofing_installation_hide_services_section){ ?>
        <section id="services-section" class="position-relative py-5">
            <div class="container">
                <div class="row">
                    <div class="col-xxl-4 col-xl-6 col-lg-7 col-md-8 col-12 align-self-center">
                        <?php if (get_theme_mod('roofing_installation_services_text') != "" || get_theme_mod('roofing_installation_services_title') != "") { ?>
                            <div class="blog-bx wow zoomIn mb-5 position-relative ps-lg-4 ps-md-4 ps-0 py-1 text-lg-start text-md-start text-center">
                                <p class="services-text text-capitalize mb-2"><?php echo esc_html(get_theme_mod('roofing_installation_services_text')); ?></p>
                                <h2 class="services-title text-capitalize"><?php echo esc_html(get_theme_mod('roofing_installation_services_title')); ?></h2>
                            </div> 
                        <?php } ?>
                    </div>
                </div>
                <div class="services-main-box gap-4">
                    <?php
                        for ($roofing_installation_i=1; $roofing_installation_i <= 5; $roofing_installation_i++) { 
                        $roofing_installation_postData=  get_theme_mod('roofing_installation_select_post'.$roofing_installation_i);
                        if($roofing_installation_postData){ ?>
                        <?php
                            $roofing_installation_args = array(
                                'p' => esc_html($roofing_installation_postData ,'roofing-installation'),
                                'posts_per_page' => 5,
                                'post_type' => 'post'
                            );
                            $roofing_installation_query = new WP_Query( $roofing_installation_args );
                            if ( $roofing_installation_query->have_posts() ) :
                            while ( $roofing_installation_query->have_posts() ) : $roofing_installation_query->the_post(); ?>
                            <div class="services-box position-relative wow zoomIn">
                                <div class="post-thumb position-relative m-0">
                                    <?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', 'roofing-installation'); ?>"/>
                                    <?php } ?>
                                    <div class="service-img-overlay position-absolute"></div>
                                </div>
                                <div class="services-main-content position-absolute">
                                    <div class="services-inner-content position-relative">
                                        <div class="icon mb-3">
                                            <?php if(get_theme_mod('roofing_installation_select_services_icon'.$roofing_installation_i) != ''){ ?>
                                                <i class="<?php echo esc_attr(get_theme_mod('roofing_installation_select_services_icon'.$roofing_installation_i)); ?>"></i>
                                            <?php } ?>
                                        </div>
                                        <div class="services-content">
                                            <h5 class="post-head text-capitalize mb-0"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h5>
                                            <p class="services-description my-2">
                                                <?php
                                                $roofing_installation_excerpt = get_the_excerpt();
                                                $roofing_installation_short_excerpt = wp_trim_words($roofing_installation_excerpt, 10, '...');
                                                echo esc_html($roofing_installation_short_excerpt);
                                                ?>
                                            </p>
                                            <a class="services-btn" href="<?php echo esc_url(get_permalink($post->ID)); ?>"><?php echo esc_html__('Read more', 'roofing-installation') ?></a>
                                        </div> 
                                    </div>
                                </div>
                            </div>   
                        <?php endwhile;
                            wp_reset_postdata();
                        endif; ?>
                    <?php }}?>
                </div>
            </div>
        </section>
    <?php } ?>
</div>
<?php get_footer(); ?>