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

get_header();
?>

<main id="primary">

    <?php 
        $automotive_parts_main_slider_wrap = absint(get_theme_mod('automotive_parts_enable_slider', 0));

        if ($automotive_parts_main_slider_wrap == 1): 
    ?>
        <section id="main-slider-wrap">
            <div class="slider-main">
                <div class="owl-carousel">
                    <?php for ($automotive_parts_main_i = 1; $automotive_parts_main_i <= 4; $automotive_parts_main_i++): ?>
                        <?php 
                        $automotive_parts_slider_image = get_theme_mod('automotive_parts_slider_image' . $automotive_parts_main_i);
                        if ($automotive_parts_slider_image): 
                        ?>
                            <div class="main-slider-inner-box">
                                <div class="container">
                                    <div class="flex-row">
                                        <div class="slider-left">
                                            <div class="main-slider-content-box">
                                                <?php if ($automotive_parts_top_text = get_theme_mod('automotive_parts_slider_top_text' . $automotive_parts_main_i)): ?>
                                                    <p class="slider-top"><?php echo esc_html($automotive_parts_top_text); ?></p>
                                                <?php endif; ?>

                                                <?php if ($automotive_parts_heading = get_theme_mod('automotive_parts_slider_heading' . $automotive_parts_main_i)): ?>
                                                    <h1><?php echo esc_html($automotive_parts_heading); ?></h1>
                                                <?php endif; ?>

                                                <?php if ($automotive_parts_text = get_theme_mod('automotive_parts_slider_text' . $automotive_parts_main_i)): ?>
                                                    <p class="slider-para"><?php echo wp_kses_post($automotive_parts_text); ?></p>
                                                <?php endif; ?>

                                                <div class="main-slider-button">
                                                    <?php 
                                                    $automotive_parts_button1_link = get_theme_mod('automotive_parts_slider_button1_link' . $automotive_parts_main_i);
                                                    $automotive_parts_button1_text = get_theme_mod('automotive_parts_slider_button1_text' . $automotive_parts_main_i);
                                                    if ($automotive_parts_button1_link && $automotive_parts_button1_text): 
                                                    ?>
                                                        <a class="slide-btn-1" href="<?php echo esc_url($automotive_parts_button1_link); ?>"><i class="fas fa-chevron-right"></i> <?php echo esc_html($automotive_parts_button1_text); ?>
                                                        </a>
                                                    <?php endif; ?>

                                                    <?php 
                                                    $automotive_parts_button2_link = get_theme_mod('automotive_parts_slider_button2_link' . $automotive_parts_main_i);
                                                    $automotive_parts_button2_text = get_theme_mod('automotive_parts_slider_button2_text' . $automotive_parts_main_i);
                                                    if ($automotive_parts_button2_link && $automotive_parts_button2_text): 
                                                    ?>
                                                        <a class="slide-btn-2" href="<?php echo esc_url($automotive_parts_button2_link); ?>"><i class="fas fa-calendar-alt"></i> <?php echo esc_html($automotive_parts_button2_text); ?>
                                                        </a>
                                                    <?php endif; ?>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="slider-right">
                                            <img src="<?php echo esc_url($automotive_parts_slider_image); ?>" alt="<?php echo esc_attr($automotive_parts_heading); ?>">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php endif; ?>
                    <?php endfor; ?>
                </div>
            </div>
        </section>
    <?php endif; ?>

   <?php 
        $automotive_parts_servicesec = get_theme_mod('automotive_parts_service_show_hide', 0);
        if ($automotive_parts_servicesec == 1) : 
        ?>
        <section id="service-section">
          <div class="container"> 
            <div class="serv-head"> 
                <?php if ( get_theme_mod('automotive_parts_section_short_title') || get_theme_mod('automotive_parts_section_title') ) : ?>
                    <i class="fas fa-cog"></i>
                <?php endif; ?>

                <?php if (get_theme_mod('automotive_parts_section_short_title')) : ?>
                    <p class="short-title"><?php echo esc_html(get_theme_mod('automotive_parts_section_short_title')); ?></p>
                <?php endif; ?> 

                <?php if (get_theme_mod('automotive_parts_section_title')) : ?>
                    <h2 class="section-title"><?php echo esc_html(get_theme_mod('automotive_parts_section_title')); ?></h2>
                <?php endif; ?> 
            </div>
            <div class="owl-carousel owl-theme">
              <?php
              $automotive_parts_post_category = get_theme_mod('automotive_parts_offer_section_category','uncategorized');
              if ($automotive_parts_post_category) :
                $automotive_parts_category_id = term_exists($automotive_parts_post_category, '');
                if ($automotive_parts_category_id !== 0 && $automotive_parts_category_id !== null) :
                  $automotive_parts_posts_to_show = get_theme_mod('automotive_parts_posts_to_show', 4);
                  $automotive_parts_page_query = new WP_Query(array(
                    'category_name' => esc_attr($automotive_parts_post_category),
                    'posts_per_page' => $automotive_parts_posts_to_show,
                  ));

                  $automotive_parts_post_count = 0;
                  if ($automotive_parts_page_query->have_posts()) :
                    while ($automotive_parts_page_query->have_posts()) : $automotive_parts_page_query->the_post(); 
                      $automotive_parts_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')); ?>" alt="<?php the_title_attribute(); ?>" />
                                  <?php else : ?>
                                    <div class="serv-color"></div>
                                  <?php endif; ?>
                                  
                                  <!-- Content and Social Icons Over Image -->
                                <div class="post-content">
                                    <h3>
                                      <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                    </h3>
                                    <div class="serv-social-media">
                                        <?php 
                                          $automotive_parts_serv_facebook_url = get_theme_mod('automotive_parts_serv_facebook_url' . $automotive_parts_post_count,'#');
                                              if ($automotive_parts_serv_facebook_url != '') { ?>
                                                  <a target="_blank" href="<?php echo esc_url($automotive_parts_serv_facebook_url); ?>">
                                                      <i class="fab fa-facebook"></i>
                                                  </a>
                                        <?php } ?>
                                        <?php 
                                          $automotive_parts_serv_twitter_url = get_theme_mod('automotive_parts_serv_twitter_url' . $automotive_parts_post_count,'#');
                                              if ($automotive_parts_serv_twitter_url != '') { ?>
                                                  <a target="_blank" href="<?php echo esc_url($automotive_parts_serv_twitter_url); ?>">
                                                      <i class="fab fa-twitter"></i>
                                                  </a>
                                        <?php } ?>
                                        <?php 
                                          $automotive_parts_serv_youtube_url = get_theme_mod('automotive_parts_serv_youtube_url' . $automotive_parts_post_count,'#');
                                              if ($automotive_parts_serv_youtube_url != '') { ?>
                                                  <a target="_blank" href="<?php echo esc_url($automotive_parts_serv_youtube_url); ?>">
                                                      <i class="fab fa-youtube"></i>
                                                  </a>
                                        <?php } ?>
                                        <?php 
                                          $automotive_parts_serv_google_plus_url = get_theme_mod('automotive_parts_serv_google_plus_url' . $automotive_parts_post_count,'#');
                                              if ($automotive_parts_serv_google_plus_url != '') { ?>
                                                  <a target="_blank" href="<?php echo esc_url($automotive_parts_serv_google_plus_url); ?>">
                                                      <i class="fab fa-google-plus-g"></i>
                                                  </a>
                                        <?php } ?>
                                        <?php 
                                          $automotive_parts_serv_linked_url = get_theme_mod('automotive_parts_serv_linked_url' . $automotive_parts_post_count,'#');
                                              if ($automotive_parts_serv_linked_url != '') { ?>
                                                  <a target="_blank" href="<?php echo esc_url($automotive_parts_serv_linked_url); ?>">
                                                      <i class="fab fa-linkedin-in"></i>
                                                  </a>
                                        <?php } ?>
                                    </div>
                                </div>
                                <div class="bottom-role">
                                    <?php
                                    $automotive_parts_role = get_theme_mod('automotive_parts_team_role' . $automotive_parts_post_count);
                                    if ($automotive_parts_role) :
                                    ?>
                                        <p class="team-role">
                                            <span class="team-name"><?php echo esc_html($automotive_parts_role); ?></span><span class="car-mechanic"><?php echo esc_html__(' - Car Mechanic', 'automotive-parts'); ?></span>
                                        </p>
                                    <?php endif; ?>
                                </div>
                            </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();
?>