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

<main id="primary">
    <?php 
    $solar_generator_main_slider_wrap = absint(get_theme_mod('solar_generator_enable_slider', 0));
    if($solar_generator_main_slider_wrap == 1): 
    ?>
        <section id="main-slider-wrap">
            <div class="owl-carousel">
                <?php for ($solar_generator_main_i=1; $solar_generator_main_i <= 3; $solar_generator_main_i++): ?>
                    <?php if ($solar_generator_slider_image = get_theme_mod('solar_generator_slider_image'.$solar_generator_main_i)): ?>
                        <div class="main-slider-inner-box">
                            <img src="<?php echo esc_url($solar_generator_slider_image); ?>" alt="<?php echo esc_attr( get_theme_mod('solar_generator_slider_heading'.$solar_generator_main_i) ); ?>">
                            <div class="main-slider-content-box wow zoomIn" data-wow-duration="2s">
                                <?php if ($solar_generator_top_text = get_theme_mod('solar_generator_slider_top_text'.$solar_generator_main_i)): ?>
                                    <p class="slider-top"><?php echo esc_html($solar_generator_top_text); ?></p>
                                <?php endif; ?>
                                <?php if ($solar_generator_heading = get_theme_mod('solar_generator_slider_heading' . $solar_generator_main_i)): ?>
                                    <h1><?php echo esc_html($solar_generator_heading); ?></h1>
                                <?php endif; ?>

                                <?php if ($solar_generator_text = get_theme_mod('solar_generator_slider_text'.$solar_generator_main_i)): ?>
                                    <p class="slider-content"><?php echo esc_html($solar_generator_text); ?></p>
                                <?php endif; ?>
                                <div class="main-slider-button">
                                    <?php if ( get_theme_mod('solar_generator_slider_button1_link'.$solar_generator_main_i) ||  get_theme_mod('solar_generator_slider_button1_text'.$solar_generator_main_i )) : ?><a class="slide-btn-1" href="<?php echo esc_url( get_theme_mod('solar_generator_slider_button1_link'.$solar_generator_main_i) ); ?>"><?php echo esc_html( get_theme_mod('solar_generator_slider_button1_text'.$solar_generator_main_i) ); ?></a><?php endif; ?>
                                    <?php if ( get_theme_mod('solar_generator_slider_button2_link'.$solar_generator_main_i) ||  get_theme_mod('solar_generator_slider_button2_text'.$solar_generator_main_i )) : ?><a class="slide-btn-2" href="<?php echo esc_url( get_theme_mod('solar_generator_slider_button2_link'.$solar_generator_main_i) ); ?>"><?php echo esc_html( get_theme_mod('solar_generator_slider_button2_text'.$solar_generator_main_i) ); ?></a><?php endif; ?>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                <?php endfor; ?>
            </div>
        </section>
    <?php endif; ?>

   <?php 
    $solar_generator_main_expert_wrap = absint(get_theme_mod('solar_generator_projetcs_sec_show', 0));
    if ($solar_generator_main_expert_wrap == 1): 
    ?>
        <section id="projetcs-sec">
            <div class="container">
                <div class="title-head">
                    <?php if( get_theme_mod('solar_generator_projetcs_main_text') != '' ){ ?>
                        <p class="project-top-text"><?php echo esc_html(get_theme_mod('solar_generator_projetcs_main_text',''));?></p>
                    <?php }?>
                    <?php if( get_theme_mod('solar_generator_projetcs_main_heading') != '' ){ ?>
                        <h2><?php echo esc_html(get_theme_mod('solar_generator_projetcs_main_heading',''));?></h2>
                    <?php }?>
                </div>
                <?php 
                $solar_generator_featured_post = absint(get_theme_mod('solar_generator_projetcs_number', 6)); 
                $solar_generator_has_tabs = true; // Flag to check if there's any tab text
                ?>
                <div class="tab">
                    <?php
                    for ( $solar_generator_j = 1; $solar_generator_j <= $solar_generator_featured_post; $solar_generator_j++ ){ 
                        $solar_generator_main_tab_text = get_theme_mod('solar_generator_projetcs_text'.$solar_generator_j);
                        if ( !empty($solar_generator_main_tab_text) ) {
                            $solar_generator_has_tabs = true; // At least one tab has text
                            ?>
                            <button class="tablinks <?php echo ($solar_generator_j === 1) ? 'active' : ''; ?>" 
                                    onclick="solar_generator_projetcs_tab(event, '<?php echo esc_attr(str_replace(' ', '-', $solar_generator_main_tab_text)); ?>')">
                                <?php echo esc_html($solar_generator_main_tab_text); ?>
                            </button>
                        <?php } 
                    } ?>
                </div>
                <?php if ($solar_generator_has_tabs): // Only show tab content if there's at least one tab ?>
                    <?php for ( $solar_generator_j = 1; $solar_generator_j <= $solar_generator_featured_post; $solar_generator_j++ ){ 
                        $solar_generator_main_tab_text = get_theme_mod('solar_generator_projetcs_text'.$solar_generator_j);
                        if ( !empty($solar_generator_main_tab_text) ) { ?>
                            <div id="<?php echo esc_attr(str_replace(' ', '-', $solar_generator_main_tab_text)); ?>" 
                                 class="tabcontent mt-3 <?php echo ($solar_generator_j === 1) ? 'active' : ''; ?>">
                                <div class="posts-wrapper">
                                    <?php
                                    $solar_generator_catData = get_theme_mod('solar_generator_projetcs_category'.$solar_generator_j);
                                    $solar_generator_catData = !empty($solar_generator_catData) ? $solar_generator_catData : 'uncategorized';
                                    if ($solar_generator_catData) {
                                        $page_query = new WP_Query(array(
                                            'category_name' => esc_html($solar_generator_catData),
                                            'posts_per_page' => 6
                                        ));

                                        while ($page_query->have_posts()) : $page_query->the_post(); ?>
                                            <div class="post-box wow zoomIn" data-wow-duration="2s">
                                                <div class="post-thumbnail">
                                                    <?php if (has_post_thumbnail()) {
                                                        the_post_thumbnail();
                                                    } else { ?>
                                                        <div class="post-color"></div>
                                                    <?php } ?>
                                                </div>
                                                <div class="post-content">
                                                    <div class="main-content">
                                                        <h3 class="post-title">
                                                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                                        </h3>
                                                        <p class="post-para"><?php echo wp_trim_words(get_the_content(), 5); ?></p>
                                                    </div>
                                                </div>
                                            </div>
                                        <?php endwhile;
                                        wp_reset_postdata();
                                    } ?>
                                </div>
                            </div>
                        <?php } 
                    } ?> 
                <?php endif; ?>   
            </div>
        </section>
    <?php endif; ?>
</main>
<?php
get_footer();
?>