<?php
/**
 * Template part for displaying slider section
 *
 * @package Farming Store
 * @subpackage farming_store
 */

$farming_store_static_image = get_template_directory_uri() . '/assets/images/slider-img.png';
$farming_store_slider_arrows = get_theme_mod('farming_store_slider_arrows', true);

?>
<?php if ($farming_store_slider_arrows) : ?>
  <section id="slider">
    <div class="container-fuild">
      <div class="owl-carousel owl-theme">
        <?php 
        $farming_store_slide_pages = array();
        for ($farming_store_count = 1; $farming_store_count <= 4; $farming_store_count++) {
          $mod = absint(get_theme_mod('farming_store_slider_page' . $farming_store_count));
          if ($mod != 0) {
            $farming_store_slide_pages[] = $mod;
          }
        }
        if (!empty($farming_store_slide_pages)) :
          $farming_store_args = array(
            'post_type' => 'page',
            'post__in' => $farming_store_slide_pages,
            'orderby' => 'post__in'
          );
          $farming_store_query = new WP_Query($farming_store_args);
          if ($farming_store_query->have_posts()) :
            while ($farming_store_query->have_posts()) : $farming_store_query->the_post(); ?>
              <div class="item">
                <div class="row m-0">
                  <div class="col-lg-6 col-md-6 col-6 slider-content-col align-self-center">
                    <div class="carousel-caption">
                      <div class="inner_carousel">
                        <?php if (get_theme_mod('farming_store_show_slider_title', true)) : ?>
                          <h1 class="mb-md-3 mb-0">
                            <a href="<?php the_permalink(); ?>">
                              <?php
                                $farming_store_title = get_the_title();
                                $farming_store_words = explode(' ', $farming_store_title);
                                if (!empty($farming_store_words)) {
                                  echo '<span class="highlight-word">' . esc_html(array_shift($farming_store_words)) . '</span> ';
                                  echo esc_html(implode(' ', $farming_store_words));
                                }
                              ?>
                            </a>
                          </h1>
                        <?php endif; ?>
                        <?php if (get_theme_mod('farming_store_show_slider_content', true)) : ?>
                          <p class="mb-0 slide-content"><?php $farming_store_excerpt = get_the_excerpt(); echo esc_html( farming_store_string_limit_words( $farming_store_excerpt, esc_attr(get_theme_mod('farming_store_slider_excerpt_length','20')))); ?></p>
                        <?php endif; ?>
                        <div class="more-btn mt-4">
                          <a class="text-capitalize me-2 mb-3 slider-btn1" href="<?php the_permalink(); ?>" target="_blank">
                              <?php esc_html_e( 'Explore Now', 'farming-store' ); ?><i class="fas fa-arrow-right ps-2"></i>
                          </a>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="col-lg-6 col-md-6 col-6 p-0 slider-img-col align-self-center">
                    <?php if (has_post_thumbnail()) : ?>
                      <img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_title_attribute(); ?>" />
                    <?php else : ?>
                      <img src="<?php echo esc_url($farming_store_static_image); ?>" alt="<?php esc_attr_e('Slider Image', 'farming-store'); ?>" />
                    <?php endif; ?>
                  </div>
                </div>
              </div>
            <?php endwhile;
            wp_reset_postdata();
          else : ?>
            <div class="no-postfound"><?php esc_html_e('No posts found', 'farming-store'); ?></div>
          <?php endif;
        endif; ?>
      </div>
    </div>
    <div class="social-media">
      <?php
        $farming_store_fb_url = get_theme_mod('farming_store_facebook_url');
        $farming_store_twitter_url = get_theme_mod('farming_store_twitter_url');
        $farming_store_flicker_url = get_theme_mod('farming_store_flicker_url');
        $farming_store_linkedin_url = get_theme_mod('farming_store_linkedin_url');

        $farming_store_fb_new_tab = esc_attr(get_theme_mod('farming_store_header_fb_new_tab', 'true'));
        $farming_store_twitter_new_tab = esc_attr(get_theme_mod('farming_store_header_twitter_new_tab', 'true'));
        $farming_store_flicker_new_tab = esc_attr(get_theme_mod('farming_store_flicker_new_tab', 'true'));
        $farming_store_linkedin_new_tab = esc_attr(get_theme_mod('farming_store_header_linkedin_new_tab', 'true'));
        if ($farming_store_fb_url || $farming_store_twitter_url || $farming_store_flicker_url || $farming_store_linkedin_url) : ?>
          <div class="icon-social">
            <?php if ($farming_store_fb_url) : ?>
                <a <?php if ($farming_store_fb_new_tab != false) : ?>target="_blank" <?php endif; ?>href="<?php echo esc_url($farming_store_fb_url); ?>"><i class="<?php echo esc_attr(get_theme_mod('farming_store_facebook_icon', 'fab fa-facebook')); ?>"></i></a>
            <?php endif; ?>

            <?php if ($farming_store_twitter_url) : ?>
                <a <?php if ($farming_store_twitter_new_tab != false) : ?>target="_blank" <?php endif; ?>href="<?php echo esc_url($farming_store_twitter_url); ?>"><i class="<?php echo esc_attr(get_theme_mod('farming_store_twitter_icon', 'fab fa-twitter')); ?>"></i></a>
            <?php endif; ?>

            <?php if ($farming_store_flicker_url) : ?>
                <a <?php if ($farming_store_flicker_new_tab != false) : ?>target="_blank" <?php endif; ?>href="<?php echo esc_url($farming_store_flicker_url); ?>"><i class="<?php echo esc_attr(get_theme_mod('farming_store_flicker_icon', 'fab fa-flickr')); ?>"></i></a>
            <?php endif; ?>

            <?php if ($farming_store_linkedin_url) : ?>
                <a <?php if ($farming_store_linkedin_url != false) : ?>target="_blank" <?php endif; ?>href="<?php echo esc_url($farming_store_linkedin_url); ?>"><i class="<?php echo esc_attr(get_theme_mod('farming_store_linkedin_icon', 'fab fa-linkedin-in')); ?>"></i></a>
          <?php endif; ?>
        </div>
      <?php endif; ?>
    </div>
    <div class="clearfix"></div>
  </section>
<?php endif; ?>