<?php
/**
 * Template part for displaying slider section
 *
 * @package Carpentry Contractor
 * @subpackage carpentry_contractor
 */

$carpentry_contractor_static_image = get_template_directory_uri() . '/assets/images/slider-img.png';
?>
<?php if (get_theme_mod('carpentry_contractor_slider_arrows', true) != '') : ?>
  <section id="main-slider" class="mb-2">
    <div class="container">
      <div class="slider-main">
        <div class="row m-0">
          <div class="col-lg-6 col-md-6 slider-content-col">
            <div class="carousel-caption">
              <div class="inner_carousel">
                  <?php 
                  $carpentry_contractor_slider_top_heading = get_theme_mod('carpentry_contractor_slider_top_heading', '');
                  if (!empty($carpentry_contractor_slider_top_heading)) : ?>
                      <p class="slidetop-text my-0">
                        <?php echo esc_html($carpentry_contractor_slider_top_heading); ?>
                      </p>
                  <?php endif; ?>
                  <?php 
                  $carpentry_contractor_slider_add_heading = get_theme_mod('carpentry_contractor_slider_add_heading', '');
                  if (!empty($carpentry_contractor_slider_add_heading)) : ?>
                      <h1 class="slider-heading my-2">
                          <?php echo esc_html($carpentry_contractor_slider_add_heading); ?>
                      </h1>
                  <?php endif; ?>
                  <?php 
                  $carpentry_contractor_slider_short_heading = get_theme_mod('carpentry_contractor_slider_short_heading', '');
                  if (!empty($carpentry_contractor_slider_short_heading)) : ?>
                    <p class="slider-content my-2">
                      <?php echo esc_html($carpentry_contractor_slider_short_heading); ?>
                    </p>
                  <?php endif; ?>
                  <div class="contact mt-4">
                    <?php 
                    $carpentry_contractor_banner_call = get_theme_mod('carpentry_contractor_banner_call', '');
                    if (!empty($carpentry_contractor_banner_call)) : ?>
                      <span class="banner-call">
                        <span class="phone">
                          <a href="tel:<?php echo esc_attr($carpentry_contractor_banner_call); ?>" class="call-btn">
                            <i class="fas fa-phone"></i>
                            <?php echo esc_html__('Call Us', 'carpentry-contractor'); ?>
                          </a>
                        </span>
                      </span>
                    <?php endif; ?>
                     <?php 
                      $carpentry_contractor_banner_btn_link = get_theme_mod('carpentry_contractor_banner_btn_link');
                      $carpentry_contractor_banner_btn_text = get_theme_mod('carpentry_contractor_banner_btn_text', esc_html__('View our work', 'carpentry-contractor'));
                      if ($carpentry_contractor_banner_btn_link) : ?>
                        <div class="slider-btn sec">
                          <a href="<?php echo esc_url($carpentry_contractor_banner_btn_link); ?>" class="slider-btn">
                              <span class="pe-2"><?php echo esc_html($carpentry_contractor_banner_btn_text); ?></span><i class="fas fa-arrow-right" aria-hidden="true"></i>
                          </a>
                        </div>
                    <?php endif; ?>
                  </div>
              </div>
            </div>
            <div id="slider">
              <div class="owl-carousel owl-theme">
                <?php 
                $carpentry_contractor_slide_pages = array();
                for ($carpentry_contractor_count = 1; $carpentry_contractor_count <= 4; $carpentry_contractor_count++) {
                  $mod = absint(get_theme_mod('carpentry_contractor_slider_page' . $carpentry_contractor_count));
                  if ($mod != 0) {
                    $carpentry_contractor_slide_pages[] = $mod;
                  }
                }
                if (!empty($carpentry_contractor_slide_pages)) :
                  $carpentry_contractor_args = array(
                    'post_type' => 'page',
                    'post__in' => $carpentry_contractor_slide_pages,
                    'orderby' => 'post__in'
                  );
                  $carpentry_contractor_query = new WP_Query($carpentry_contractor_args);
                  if ($carpentry_contractor_query->have_posts()) :
                    while ($carpentry_contractor_query->have_posts()) : $carpentry_contractor_query->the_post(); ?>
                      <div class="item">
                        <div class="row m-0">
                          <div class="col-lg-4 col-md-5 col-5 slider-img-box align-self-center">
                            <div class="slider-main-img">
                              <?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($carpentry_contractor_static_image); ?>" alt="<?php esc_attr_e('Slider Image', 'carpentry-contractor'); ?>" />
                              <?php endif; ?>
                            </div>
                          </div>
                          <div class="col-lg-8 col-md-7 col-7 inner-slider-content align-self-center">
                            <div class="carousel-caption">
                              <div class="inner_carousel">
                                <h3 class="mb-1">
                                  <a href="<?php the_permalink(); ?>" class="text-capitalize"><?php the_title();?></a>
                                </h3>
                                <p class="mb-0 slide-detail"><?php echo wp_kses_post(wp_trim_words(get_the_content(), 10)); ?></p>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    <?php endwhile;
                    wp_reset_postdata();
                  else : ?>
                    <div class="no-postfound"><?php esc_html_e('No posts found', 'carpentry-contractor'); ?></div>
                  <?php endif;
                endif; ?>
              </div>
            </div>
          </div>
          <div class="col-lg-6 col-md-6 slider-img-col px-0 mt-md-0 mt-4">
            <?php if( get_theme_mod( 'carpentry_contractor_banner_image_select') != '') { ?>
              <img src="<?php echo esc_url(get_theme_mod('carpentry_contractor_banner_image_select')); ?>" alt="<?php esc_attr_e( 'Banner Image','carpentry-contractor' ); ?>" />
            <?php } ?>
            <div class="social-media">
              <?php                 
                $carpentry_contractor_header_fb_new_tab = esc_attr(get_theme_mod('carpentry_contractor_header_fb_new_tab','true'));
                $carpentry_contractor_header_twt_new_tab = esc_attr(get_theme_mod('carpentry_contractor_header_twt_new_tab','true'));
                $carpentry_contractor_header_ins_new_tab = esc_attr(get_theme_mod('carpentry_contractor_header_ins_new_tab','true'));
                $carpentry_contractor_header_ut_new_tab = esc_attr(get_theme_mod('carpentry_contractor_header_ut_new_tab','true'));
                $carpentry_contractor_header_pint_new_tab = esc_attr(get_theme_mod('carpentry_contractor_header_pint_new_tab','true'));
                ?>
              <?php if( get_theme_mod( 'carpentry_contractor_facebook_url' ) != '') { ?>
                <span class="social-text me-3"><?php esc_html_e('Follow Us:','carpentry-contractor'); ?></span>
                <a <?php if($carpentry_contractor_header_fb_new_tab != false ) { ?>target="_blank" <?php } ?>href="<?php echo esc_url( get_theme_mod( 'carpentry_contractor_facebook_url','' ) ); ?>"><i class="<?php echo esc_attr(get_theme_mod('carpentry_contractor_facebook_icon','fab fa-facebook-f')); ?>"></i></a>
              <?php } ?>
              <?php if( get_theme_mod( 'carpentry_contractor_twitter_url' ) != '') { ?>
                <a <?php if($carpentry_contractor_header_twt_new_tab != false ) { ?>target="_blank" <?php } ?>href="<?php echo esc_url( get_theme_mod( 'carpentry_contractor_twitter_url','' ) ); ?>"><i class="<?php echo esc_attr(get_theme_mod('carpentry_contractor_twitter_icon','fab fa-twitter')); ?>"></i></a>
              <?php } ?>
              <?php if( get_theme_mod( 'carpentry_contractor_instagram_url' ) != '') { ?>
                <a <?php if($carpentry_contractor_header_ins_new_tab != false ) { ?>target="_blank" <?php } ?>href="<?php echo esc_url( get_theme_mod( 'carpentry_contractor_instagram_url','' ) ); ?>"><i class="<?php echo esc_attr(get_theme_mod('carpentry_contractor_instagram_icon','fab fa-instagram')); ?>"></i></a>
              <?php } ?>
              <?php if( get_theme_mod( 'carpentry_contractor_pint_url' ) != '') { ?>
                <a <?php if($carpentry_contractor_header_pint_new_tab != false ) { ?>target="_blank" <?php } ?>href="<?php echo esc_url( get_theme_mod( 'carpentry_contractor_pint_url','' ) ); ?>"><i class="<?php echo esc_attr(get_theme_mod('carpentry_contractor_pint_icon','fab fa-pinterest-p')); ?>"></i></a>
              <?php } ?>
            </div>
            <div class="bold-img-text">
              <?php 
                $carpentry_contractor_slider_img_highlight_text = get_theme_mod('carpentry_contractor_slider_img_highlight_text', '');
                if (!empty($carpentry_contractor_slider_img_highlight_text)) :
                  // Split text into words
                  $carpentry_contractor_words = explode(' ', $carpentry_contractor_slider_img_highlight_text);
                  // Extract the first word and rest
                  $carpentry_contractor_first_word = array_shift($carpentry_contractor_words);
                  $carpentry_contractor_remaining_text = implode(' ', $carpentry_contractor_words);
                ?>
                  <h2 class="highlight-img-text">
                    <span class="first-word"><?php echo esc_html($carpentry_contractor_first_word); ?></span></br> <?php echo esc_html($carpentry_contractor_remaining_text); ?>
                  </h2>
                <?php endif; ?>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>
<?php endif; ?>