<?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 Business Incubator
 */

get_header(); ?>

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

        if ($business_incubator_banner && $business_incubator_banner_pageboxes) { ?>
        <section id="banner-cat" class="position-relative">
            <?php
            $business_incubator_querymed = new WP_Query(array(
                'page_id' => esc_attr($business_incubator_banner_pageboxes)
            ));
            while ($business_incubator_querymed->have_posts()) : $business_incubator_querymed->the_post(); ?>
                <div class="container">
                    <div class="row">
                        <div class="col-xxl-4 col-xl-5 col-lg-6 col-md-6 col-12 align-self-center">
                            <div class="bannerbox text-lg-start text-md-start text-center">
                                <h1 class="mb-3 text-capitalize banner-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                                <?php
                                    $business_incubator_trimexcerpt = get_the_excerpt();
                                    $business_incubator_shortexcerpt = wp_trim_words($business_incubator_trimexcerpt, 38);
                                    echo '<p class="banner-content mb-4">' . esc_html($business_incubator_shortexcerpt) . '</p>';
                                ?>
                                <div class="bannerbtn">
                                    <?php
                                        $business_incubator_button_text = get_theme_mod('business_incubator_button_text', 'Our Service');
                                        $business_incubator_button_link_banner = esc_url(get_theme_mod('business_incubator_button_link_banner', get_permalink()));
                                        if ($business_incubator_button_text || !empty($business_incubator_button_link_banner)) { ?>
                                        <?php if ($business_incubator_button_text != '') { ?>
                                            <a href="<?php echo esc_url($business_incubator_button_link_banner); ?>" class="button">
                                                <?php echo esc_html($business_incubator_button_text); ?>
                                                <span class="screen-reader-text"><?php echo esc_html($business_incubator_button_text); ?></span>
                                            </a>
                                        <?php } ?>
                                    <?php } ?>
                                </div>
                            </div>
                        </div>
                        <div class="offset-xxl-2 offset-xl-1 col-xxl-6 col-xl-6 col-lg-6 col-md-6 col-12 align-self-center text-center banner-img">
                            <?php if (has_post_thumbnail()) { ?>
                                <?php the_post_thumbnail('full bnr-inner-img'); ?>
                            <?php } ?>
                        </div>
                    </div>
                </div>
            <?php endwhile;
                wp_reset_postdata();
            ?>
        </section>
    <?php } ?>

    <!-- Startup Section -->
    <?php 
    $business_incubator_hide_startup_section = get_theme_mod('business_incubator_disabled_startup_section', false);
    if ($business_incubator_hide_startup_section) { ?>
        <section id="startup-section" class="py-5 position-relative">
            <div class="container">
                <div class="heading-box mb-5 text-center">
                    <?php if (get_theme_mod('business_incubator_startup_sec_text') != "") { ?>
                        <p class="startup-text text-capitalize mb-2">
                            <?php echo esc_html(get_theme_mod('business_incubator_startup_sec_text')); ?>
                        </p>
                    <?php } ?>
                    <?php if (get_theme_mod('business_incubator_startup_sec_title') != "") { ?>
                        <h2 class="startup-title text-capitalize">
                            <?php echo esc_html(get_theme_mod('business_incubator_startup_sec_title')); ?>
                        </h2>
                    <?php } ?>
                </div>
                <div class="row">
                    <?php
                        for ($business_incubator_i=1; $business_incubator_i <= 3; $business_incubator_i++) { 
                        $business_incubator_postData=  get_theme_mod('business_incubator_select_post'.$business_incubator_i);
                        if($business_incubator_postData){ ?>
                        <?php
                            $business_incubator_args = array(
                                'p' => esc_html($business_incubator_postData ,'business-incubator'),
                                'posts_per_page' => 3,
                                'post_type' => 'post'
                            );
                            $business_incubator_query = new WP_Query( $business_incubator_args );
                            if ( $business_incubator_query->have_posts() ) :
                            while ( $business_incubator_query->have_posts() ) : $business_incubator_query->the_post(); ?>
                            <div class="col-xl-4 col-lg-4 col-md-4 col-12 mb-5">   
                                <div class="startup-box">
                                    <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-image.png" alt="<?php echo esc_attr( 'post-image', 'business-incubator'); ?>"/>
                                        <?php } ?>
                                        <div class="icon position-absolute">
                                            <?php if(get_theme_mod('business_incubator_select_startup_icon'.$business_incubator_i) != ''){ ?>
                                                <i class="<?php echo esc_attr(get_theme_mod('business_incubator_select_startup_icon'.$business_incubator_i)); ?>"></i>
                                            <?php } ?>
                                        </div>
                                    </div>
                                    <div class="startup-main-content">
                                        <div class="startup-content p-4 mx-3">
                                            <h3 class="post-head text-capitalize mt-2"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
                                            <p class="startup-description my-4">
                                                <?php
                                                $business_incubator_excerpt = get_the_excerpt();
                                                $business_incubator_short_excerpt = wp_trim_words($business_incubator_excerpt, 15, '...');
                                                echo esc_html($business_incubator_short_excerpt);
                                                ?>
                                            </p>
                                            <a class="startup-btn text-capitalize" href="<?php echo esc_url(get_permalink($post->ID)); ?>"><?php echo esc_html__('read more', 'business-incubator') ?></a>
                                        </div> 
                                    </div>
                                </div>   
                            </div>
                        <?php endwhile;
                        wp_reset_postdata();
                        endif; ?>
                    <?php }}?>
                </div>
            </div>
        </section>
    <?php } ?>
</div>
<?php get_footer(); ?>