<?php
/**
 * Template part for displaying slider section.
 *
 * @package appliances_store
 */

$appliances_store_static_image = get_stylesheet_directory_uri() . '/assets/images/slider-img.png';
$appliances_store_slider_arrows = get_theme_mod('appliances_store_slider_arrows', true);

if ($appliances_store_slider_arrows) : ?>
    <section id="main-slider">
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-md-8 align-self-center">
            <div id="slider">
                <?php 
                $appliances_store_slide_pages = array();
                $appliances_store_mod = absint(get_theme_mod('appliances_store_slider_page'));
                if ($appliances_store_mod !== 0) {
                    $appliances_store_slide_pages[] = $appliances_store_mod;
                }

                if (!empty($appliances_store_slide_pages)) :
                    $appliances_store_args = array(
                        'post_type'      => 'page',
                        'post__in'       => $appliances_store_slide_pages,
                        'orderby'        => 'post__in',
                        'posts_per_page' => -1,
                    );
                    $appliances_store_query = new WP_Query($appliances_store_args);

                    if ($appliances_store_query->have_posts()) :
                        while ($appliances_store_query->have_posts()) : $appliances_store_query->the_post(); ?>
                            <div class="item">
                                <div class="row">
                                    <div class="col-lg-6 col-md-7 col-12 slider-content-col align-self-center">
                                        <div class="carousel-caption">
                                            <div class="inner_carousel pe-lg-4 pe-md-0">
                                              <?php 
                                                $appliances_store_slider_short_heading = get_theme_mod('appliances_store_slider_short_heading', '');
                                                if (!empty($appliances_store_slider_short_heading)) : ?>
                                                    <p class="slidetop-text text-capitalize mb-md-0 mt-md-0 mb-1">
                                                        <?php echo esc_html($appliances_store_slider_short_heading); ?>
                                                    </p>
                                                <?php endif; ?>
                                                <?php if (get_theme_mod('appliances_store_show_slider_title', true)) : ?>
                                                    <h1 class="mt-md-2 mb-3">
                                                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                                    </h1>
                                                <?php endif; ?>
                                                <?php if (get_theme_mod('appliances_store_show_slider_content', true)) : ?>
                                                    <p class="slide-content"><?php $appliances_store_excerpt = get_the_excerpt(); echo esc_html( appliances_store_string_limit_words( $appliances_store_excerpt, esc_attr(get_theme_mod('appliances_store_slider_excerpt_length','18')))); ?></p>
                                                <?php endif; ?>
                                                <div class="countdowntimer mt-2">
                                                    <p id="timer" class="countdown">
                                                      <?php
                                                      $appliances_store_dateday = get_theme_mod('appliances_store_product_clock_timer_end'); ?>
                                                      <input type="hidden" class="date" value="<?php echo esc_html($appliances_store_dateday); ?>">
                                                    </p>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-5 col-12 slider-img-col p-md-0">
                                        <?php if (has_post_thumbnail()) : ?>
                                            <?php the_post_thumbnail('full', array('alt' => esc_attr(get_the_title()))); ?>
                                        <?php else : ?>
                                            <img src="<?php echo esc_url($appliances_store_static_image); ?>" alt="<?php esc_attr_e('Slider Image', 'appliances-store'); ?>" />
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        <?php endwhile;
                        wp_reset_postdata();
                    endif; ?>
                <?php endif; ?>
            </div>
          </div>
          <div class="col-lg-4 col-md-4 align-self-center">
            <div class="slide-banner">
              <?php if( get_theme_mod( 'appliances_store_discount_sale_img1') != '') { ?>
                <div class="banner-1 mb-3 mb-md-0 position-relative">
                  <div class="product-img">
                    <img src="<?php echo esc_url(get_theme_mod('appliances_store_discount_sale_img1')); ?>" alt="<?php esc_attr_e( 'Banner Product Image','appliances-store' ); ?>" />
                        <div class="product-content first">
                          <?php if (get_theme_mod('appliances_store_product_sale_discount_title1') !== '') : ?>
                            <h2 class="my-2"><?php echo esc_html(get_theme_mod('appliances_store_product_sale_discount_title1')); ?></h2>
                          <?php endif; ?>
                          <div class="product-btn mt-3" data-wow-duration="2s">
                            <?php if(get_theme_mod('appliances_store_product_btn_text1') != ''){ ?>
                              <a href="<?php echo esc_url(get_theme_mod('appliances_store_product_btn_link1')); ?>"><?php echo esc_html(get_theme_mod('appliances_store_product_btn_text1')); ?><span class="screen-reader-text"><?php echo esc_html(get_theme_mod('appliances_store_product_btn_text1')); ?></span></a>
                            <?php }?>
                          </div>
                        </div>
                    <?php if (get_theme_mod('appliances_store_product_sale_discount') !== '') : ?>
                        <div class="top-discount">
                            <p class="discount-text mb-0">
                                <?php 
                                $appliances_store_discount = get_theme_mod('appliances_store_product_sale_discount');
                                if ($appliances_store_discount) : ?>
                                    <span class="offer-text text-start"><?php echo esc_html__('Offer', 'appliances-store'); ?></span><br>
                                    <span class="discount-value text-center"><?php echo esc_html($appliances_store_discount); ?></span><br>
                                    <span class="off-text text-end"><?php echo esc_html__('OFF', 'appliances-store'); ?></span>
                                <?php endif; ?>
                            </p>
                        </div>
                    <?php endif; ?>
                  </div>
                </div>
              <?php } ?>
            </div>
          </div>
        </div>
      </div>
    </section>
<?php endif; ?>