<?php
/**
 * Template Name: Home Page
 */

get_header();
?>

<main id="primary">
    <?php 
    $handyman_agency_main_slider_wrap = absint(get_theme_mod('handyman_agency_enable_slider', 0));
    if($handyman_agency_main_slider_wrap == 1): 
    ?>
        <section id="main-slider-wrap">
            <div class="owl-carousel">
                <?php for ($handyman_agency_main_i=1; $handyman_agency_main_i <= 3; $handyman_agency_main_i++): ?>
                    <?php if ($handyman_agency_slider_image = get_theme_mod('handyman_agency_slider_image'.$handyman_agency_main_i)): ?>
                        <div class="main-slider-inner-box">
                            <img src="<?php echo esc_url($handyman_agency_slider_image); ?>" alt="<?php echo esc_attr( get_theme_mod('handyman_agency_slider_heading'.$handyman_agency_main_i) ); ?>">
                            <div class="main-slider-content-box">
                                <?php if ($handyman_agency_top_text = get_theme_mod('handyman_agency_slider_top_text'.$handyman_agency_main_i)): ?>
                                    <p class="slider-top"><?php echo esc_html($handyman_agency_top_text); ?></p>
                                <?php endif; ?>
                                <?php if ($handyman_agency_heading = get_theme_mod('handyman_agency_slider_heading' . $handyman_agency_main_i)): ?>
                                    <h1><?php echo esc_html($handyman_agency_heading); ?></h1>
                                <?php endif; ?>
                                <?php if ($handyman_agency_text = get_theme_mod('handyman_agency_slider_text'.$handyman_agency_main_i)): ?>
                                    <p class="slider-content"><?php echo esc_html($handyman_agency_text); ?></p>
                                <?php endif; ?>
                                <div class="main-slider-button">
                                    <?php if ( get_theme_mod('handyman_agency_slider_button1_link'.$handyman_agency_main_i) ||  get_theme_mod('handyman_agency_slider_button1_text'.$handyman_agency_main_i )) : ?><a class="slide-btn-1" href="<?php echo esc_url( get_theme_mod('handyman_agency_slider_button1_link'.$handyman_agency_main_i) ); ?>"><?php echo esc_html( get_theme_mod('handyman_agency_slider_button1_text'.$handyman_agency_main_i) ); ?></a><?php endif; ?>
                                    <?php 
                                        $handyman_agency_button2_link = get_theme_mod('handyman_agency_slider_button2_link' . $handyman_agency_main_i);
                                        $handyman_agency_button2_text = get_theme_mod('handyman_agency_slider_button2_text' . $handyman_agency_main_i);
                                        if ($handyman_agency_button2_link || $handyman_agency_button2_text): 
                                        ?>
                                            <a class="slide-btn-2" href="<?php echo esc_url($handyman_agency_button2_link); ?>">
                                                <?php echo esc_html($handyman_agency_button2_text); ?>
                                            </a>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                <?php endfor; ?>
            </div>
        </section>
    <?php endif; ?>

    <?php 
        $handyman_agency_servicesec = get_theme_mod('handyman_agency_service_show_hide', 0);
        if ($handyman_agency_servicesec == 1) : 
        ?>
        <section id="service-section">
          <div class="container"> 
            <div class="serv-head"> 
                <div class="serv-left">
                  <?php if (get_theme_mod('handyman_agency_section_title')) : ?>
                    <h2 class="section-title"><i class="fas fa-tools"></i><?php echo esc_html(get_theme_mod('handyman_agency_section_title')); ?></h2>
                  <?php endif; ?> 
                </div>
                <div class="serv-right">
                    <span class="view-more-button">
                        <?php if (get_theme_mod('handyman_agency_view_more_button_link') && get_theme_mod('handyman_agency_view_more_button_text', 'VIEW MORE WORK')): ?>
                            <a href="<?php echo esc_url(get_theme_mod('handyman_agency_view_more_button_link')); ?>"><?php echo esc_html(get_theme_mod('handyman_agency_view_more_button_text', 'VIEW MORE WORK')); ?></a>
                        <?php endif; ?>
                    </span>
                </div>
            </div>
            <div class="owl-carousel owl-theme">
              <?php
              $handyman_agency_post_category = get_theme_mod('handyman_agency_offer_section_category','uncategorized');
              if ($handyman_agency_post_category) :
                $handyman_agency_category_id = term_exists($handyman_agency_post_category, 'category');
                if ($handyman_agency_category_id !== 0 && $handyman_agency_category_id !== null) :
                  $handyman_agency_posts_to_show = get_theme_mod('handyman_agency_posts_to_show', 4);
                  $handyman_agency_page_query = new WP_Query(array(
                    'category_name' => esc_attr($handyman_agency_post_category),
                    'posts_per_page' => $handyman_agency_posts_to_show,
                  ));

                  $handyman_agency_post_count = 0;
                  if ($handyman_agency_page_query->have_posts()) :
                    while ($handyman_agency_page_query->have_posts()) : $handyman_agency_page_query->the_post(); 
                      $handyman_agency_post_count++;
              ?>
                      <div class="item">
                        <div class="serv-box">
                            <div class="post-main-img">
                                <?php if (has_post_thumbnail()) : ?>
                                  <img src="<?php echo esc_url(get_the_post_thumbnail_url(null, 'full')); ?>" />
                                <?php else : ?>
                                  <div class="serv-color"></div>
                                <?php endif; ?>
                                <div class="post-content">
                                    <h3 class="text-capitalize"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                    <?php if ($handyman_agency_team_role = get_theme_mod('handyman_agency_team_role' . $handyman_agency_post_count)) { ?>
                                        <p class="team-role"><?php echo esc_html($handyman_agency_team_role); ?></p>
                                    <?php } ?>
                                </div>
                            </div>
                            <div class="serv-social-media">
                              <?php 
                                  $handyman_agency_serv_facebook_url = get_theme_mod('handyman_agency_serv_facebook_url' . $handyman_agency_post_count);
                                      if ($handyman_agency_serv_facebook_url != '') { ?>
                                          <a target="_blank" href="<?php echo esc_url($handyman_agency_serv_facebook_url); ?>">
                                              <i class="fab fa-facebook"></i>
                                          </a>
                              <?php } ?>
                              <?php 
                                  $handyman_agency_serv_twitter_url = get_theme_mod('handyman_agency_serv_twitter_url' . $handyman_agency_post_count);
                                      if ($handyman_agency_serv_twitter_url != '') { ?>
                                          <a target="_blank" href="<?php echo esc_url($handyman_agency_serv_twitter_url); ?>">
                                              <i class="fab fa-twitter"></i>
                                          </a>
                              <?php } ?>
                              <?php 
                                  $handyman_agency_serv_insta_url = get_theme_mod('handyman_agency_serv_insta_url' . $handyman_agency_post_count);
                                      if ($handyman_agency_serv_insta_url != '') { ?>
                                          <a target="_blank" href="<?php echo esc_url($handyman_agency_serv_insta_url); ?>">
                                              <i class="fab fa-instagram"></i>
                                          </a>
                              <?php } ?>
                              <?php 
                                  $handyman_agency_serv_linked_url = get_theme_mod('handyman_agency_serv_linked_url' . $handyman_agency_post_count);
                                      if ($handyman_agency_serv_linked_url != '') { ?>
                                          <a target="_blank" href="<?php echo esc_url($handyman_agency_serv_linked_url); ?>">
                                              <i class="fab fa-linkedin-in"></i>
                                          </a>
                              <?php } ?>
                              <?php 
                                  $handyman_agency_serv_youtube_url = get_theme_mod('handyman_agency_serv_youtube_url' . $handyman_agency_post_count);
                                      if ($handyman_agency_serv_youtube_url != '') { ?>
                                          <a target="_blank" href="<?php echo esc_url($handyman_agency_serv_youtube_url); ?>">
                                              <i class="fab fa-youtube"></i>
                                          </a>
                              <?php } ?>
                            </div>
                        </div>
                      </div>
                    <?php endwhile; ?>
                    <?php wp_reset_postdata(); ?>
                  <?php else : ?>
                    <div class="no-postfound"></div>
                  <?php endif; ?>
                <?php endif; ?>
              <?php endif; ?>
            </div>
          </div>
        </section>
    <?php endif; ?>
</main>
<?php
get_footer();
?>