<?php
/**
 * Template part for displaying slider section
 *
 * @package NGO Organization
 * @subpackage ngo_organization
 */

?>
<?php
$ngo_organization_static_image = get_stylesheet_directory_uri() . '/assets/images/sliderimage.png';

if ( get_theme_mod( 'ngo_organization_slider_arrows', true) ) :
?>
<section id="slider">
  <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
    <?php
    $ngo_organization_slide_pages = array();
    for ( $ngo_organization_count = 1; $ngo_organization_count <= 4; $ngo_organization_count++ ) {
        $ngo_organization_mod = intval( get_theme_mod( 'ngo_organization_slider_page' . $ngo_organization_count ) );
        if ( 'page-none-selected' != $ngo_organization_mod ) {
            $ngo_organization_slide_pages[] = $ngo_organization_mod;
        }
    }
    if ( !empty( $ngo_organization_slide_pages ) ) :
        $ngo_organization_args = array(
            'post_type' => 'page',
            'post__in' => $ngo_organization_slide_pages,
            'orderby' => 'post__in'
        );
        $ngo_organization_query = new WP_Query( $ngo_organization_args );
        if ( $ngo_organization_query->have_posts() ) :
            $i = 1;
    ?>
    <div class="carousel-inner" role="listbox">
      <?php while ( $ngo_organization_query->have_posts() ) : $ngo_organization_query->the_post(); ?>
      <div class="carousel-item <?php if ( $i == 1 ) echo 'active'; ?>">
        <?php if ( has_post_thumbnail() ) { ?>
        <img src="<?php the_post_thumbnail_url( 'full' ); ?>" alt="<?php the_title(); ?>" />
        <?php } else { ?>
        <img src="<?php echo esc_url( $ngo_organization_static_image ); ?>" alt="<?php esc_attr_e( 'Default Image', 'ngo-organization' ); ?>" />
        <?php } ?>
        <div class="carousel-caption <?php echo esc_attr( get_theme_mod( 'ngo_organization_slider_content_layout', 'CENTER-ALIGN' ) ); ?>">
          <div class="inner_carousel">
            <?php if (get_theme_mod('ngo_organization_show_slider_title', true)) : ?>
                <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
              <?php endif; ?>
              <?php if (get_theme_mod('ngo_organization_show_slider_content', true)) : ?>
                <p><?php echo wp_trim_words( get_the_content(),18 );?></p>
              <?php endif; ?>
            <?php if ( get_theme_mod( 'ngo_organization_slider_button', true ) ) { ?>
            <div class="more-btn">
              <a href="<?php the_permalink(); ?>"><?php esc_html_e( 'READ MORE', 'ngo-organization' ); ?></a>
            </div>
            <?php } ?>
          </div>
        </div>
      </div>
      <?php $i++; endwhile; wp_reset_postdata(); ?>
    </div>
    <?php else : ?>
    <div class="no-postfound"><?php esc_html_e( 'No posts found', 'ngo-organization' ); ?></div>
    <?php endif; endif; ?>
    <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="prev">
      <i class="fas fa-angle-left" aria-hidden="true"></i>
      <span class="screen-reader-text"><?php echo esc_html('Previous', 'ngo-organization'); ?></span>
    </button>
    <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="next">
      <i class="fas fa-angle-right" aria-hidden="true"></i>
      <span class="screen-reader-text"><?php echo esc_html('Next', 'ngo-organization'); ?></span>
    </button>
  <div class="clearfix"></div>
  <div class="social-links">
    <span class="media-links">
      <?php
      $ngo_organization_facebook_new_tab = get_theme_mod( 'ngo_organization_facebook_new_tab', 'true' );
      $ngo_organization_twitter_new_tab = get_theme_mod( 'ngo_organization_twitter_new_tab', 'true' );
      $ngo_organization_instagram_new_tab = get_theme_mod( 'ngo_organization_instagram_new_tab', 'true' );
      $ngo_organization_youtube_new_tab = get_theme_mod( 'ngo_organization_youtube_new_tab', 'true' );
      $ngo_organization_pint_new_tab = get_theme_mod( 'ngo_organization_pint_new_tab', 'true' );

      if ( get_theme_mod( 'ngo_organization_facebook_url' ) ) { ?>
      <a <?php if ( $ngo_organization_facebook_new_tab ) echo 'target="_blank"'; ?> href="<?php echo esc_url( get_theme_mod( 'ngo_organization_facebook_url' ) ); ?>"><i class="<?php echo esc_attr( get_theme_mod( 'ngo_organization_facebook_icon', 'fab fa-facebook-f' ) ); ?> me-2"></i></a>
      <?php }
      if ( get_theme_mod( 'ngo_organization_twitter_url' ) ) { ?>
      <a <?php if ( $ngo_organization_twitter_new_tab ) echo 'target="_blank"'; ?> href="<?php echo esc_url( get_theme_mod( 'ngo_organization_twitter_url' ) ); ?>"><i class="<?php echo esc_attr( get_theme_mod( 'ngo_organization_twitter_icon', 'fab fa-twitter' ) ); ?> me-2"></i></a>
      <?php }
      if ( get_theme_mod( 'ngo_organization_instagram_url' ) ) { ?>
      <a <?php if ( $ngo_organization_instagram_new_tab ) echo 'target="_blank"'; ?> href="<?php echo esc_url( get_theme_mod( 'ngo_organization_instagram_url' ) ); ?>"><i class="<?php echo esc_attr( get_theme_mod( 'ngo_organization_instagram_icon', 'fab fa-instagram' ) ); ?> me-2"></i></a>
      <?php }
      if ( get_theme_mod( 'ngo_organization_youtube_url' ) ) { ?>
      <a <?php if ( $ngo_organization_youtube_new_tab ) echo 'target="_blank"'; ?> href="<?php echo esc_url( get_theme_mod( 'ngo_organization_youtube_url' ) ); ?>"><i class="<?php echo esc_attr( get_theme_mod( 'ngo_organization_youtube_icon', 'fab fa-youtube' ) ); ?> me-2"></i></a>
      <?php }
      if ( get_theme_mod( 'ngo_organization_pint_url' ) ) { ?>
      <a <?php if ( $ngo_organization_pint_new_tab ) echo 'target="_blank"'; ?> href="<?php echo esc_url( get_theme_mod( 'ngo_organization_pint_url' ) ); ?>"><i class="<?php echo esc_attr( get_theme_mod( 'ngo_organization_pint_icon', 'fab fa-pinterest' ) ); ?> me-2"></i></a>
      <?php } ?>
    </span>
  </div>
</section>
<?php
endif;
?>
