<?php
/**
 * Template part for displaying slider section
 *
 * @package Marketing Campaigns
 * @subpackage marketing_campaigns
 */

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

?>
<?php if ($marketing_campaigns_slider_arrows) : ?>
  <section id="slider" style="background-image: url('<?php echo get_stylesheet_directory_uri(); ?>/assets/images/sliderbg1.png');">
    <div class="container-fuild">
      <div class="owl-carousel owl-theme">
        <?php 
        $marketing_campaigns_slide_pages = array();
        for ($marketing_campaigns_count = 1; $marketing_campaigns_count <= 4; $marketing_campaigns_count++) {
          $mod = absint(get_theme_mod('marketing_campaigns_slider_page' . $marketing_campaigns_count));
          if ($mod != 0) {
            $marketing_campaigns_slide_pages[] = $mod;
          }
        }

        if (!empty($marketing_campaigns_slide_pages)) :
          $marketing_campaigns_args = array(
            'post_type' => 'page',
            'post__in' => $marketing_campaigns_slide_pages,
            'orderby' => 'post__in'
          );
          $marketing_campaigns_query = new WP_Query($marketing_campaigns_args);
          if ($marketing_campaigns_query->have_posts()) :
            while ($marketing_campaigns_query->have_posts()) : $marketing_campaigns_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('marketing_campaigns_slider_short_heading')) : ?>
                          <p class="slidetop-text mb-2 text-uppercase"><?php echo esc_html(get_theme_mod('marketing_campaigns_slider_short_heading')); ?></p>
                        <?php endif; ?>
                        <?php if (get_theme_mod('marketing_campaigns_show_slider_title', true)) : ?>
                          <h1 class="mb-md-3 mb-0">
                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                          </h1>
                        <?php endif; ?>
                        <?php if (get_theme_mod('marketing_campaigns_show_slider_content', true)) : ?>
                          <p class="mb-0 slide-content"><?php $marketing_campaigns_excerpt = get_the_excerpt(); echo esc_html( marketing_campaigns_string_limit_words( $marketing_campaigns_excerpt, esc_attr(get_theme_mod('marketing_campaigns_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( 'Contact Us', 'marketing-campaigns' ); ?>
                          </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($marketing_campaigns_static_image); ?>" alt="<?php esc_attr_e('Slider Image', 'marketing-campaigns'); ?>" />
                    <?php endif; ?>
                  </div>
                </div>
              </div>
            <?php endwhile;
            wp_reset_postdata();
          else : ?>
            <div class="no-postfound"><?php esc_html_e('No posts found', 'marketing-campaigns'); ?></div>
          <?php endif;
        endif; ?>
      </div>
    </div>
    <div class="clearfix"></div>
  </section>
<?php endif; ?>