<?php
/**
 * Template Name: Custom Home Page
 */
get_header(); ?>

<main id="content">
  <?php if( get_theme_mod('ngo_charity_donation_slider_arrows') != ''){ ?>
    <section id="slider">
      <span class="design-right"></span>
      <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel"> 
        <?php
          for ( $i = 1; $i <= 4; $i++ ) {
            $mod =  get_theme_mod( 'ngo_charity_donation_post_setting' . $i );
            if ( 'page-none-selected' != $mod ) {
              $ngo_charity_donation_slide_post[] = $mod;
            }
          }
           if( !empty($ngo_charity_donation_slide_post) ) :
          $args = array(
            'post_type' =>array('post'),
            'post__in' => $ngo_charity_donation_slide_post
          );
          $query = new WP_Query( $args );
          if ( $query->have_posts() ) :
            $i = 1;
        ?>
        <div class="carousel-inner" role="listbox">
          <?php  while ( $query->have_posts() ) : $query->the_post(); ?>
          <div <?php if($i == 1){echo 'class="carousel-item active"';} else{ echo 'class="carousel-item"';}?>>
            <div class="row">              
              <div class="col-lg-6 col-md-6 col-sm-6 slide-content ">
                <div class="carousel-caption text-center text-md-left text-sm-left px-5 px-md-3">
                  <h2 class="slider-title"><?php the_title();?></h2>
                  <p class="mb-0"><?php echo esc_html(wp_trim_words(get_the_content(),'20') );?></p>
                  <div class="home-btn text-center text-md-left text-sm-left my-4">
                    <a class="py-3 px-4" href="<?php the_permalink(); ?>"><?php echo esc_html('DONATE NOW','charity-foundation'); ?></a>
                  </div>
                </div>
              </div>
              <div class="col-lg-6 col-md-6 col-sm-6 image-content">
                <img src="<?php esc_url(the_post_thumbnail_url('full')); ?>"/>
              </div>
            </div>
          </div>
          <?php $i++; endwhile;
          wp_reset_postdata();?>
        </div>
        <?php else : ?>
        <div class="no-postfound"></div>
          <?php endif;
        endif;?>
          <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"><i class="fas fa-long-arrow-alt-left"></i></span>
          </a>
          <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"><i class="fas fa-long-arrow-alt-right"></i></span>
          </a>
      </div>
      <div class="clearfix"></div>
    </section>
  <?php }?>

  <section id="volunteer" class="py-5">
    <div class="container">
      <div class="row">
        <div class="col-lg-4 col-md-4 col-sm-4 align-self-center">
          <?php if( get_theme_mod('ngo_charity_donation_volunteer_title') != '' ){ ?>
            <h3 class="mb-4 text-center text-md-left"><?php echo esc_html(get_theme_mod('ngo_charity_donation_volunteer_title','')); ?></h3>
          <?php }?>
          <?php if( get_theme_mod('ngo_charity_donation_volunteer_btn_link') != '' || get_theme_mod('ngo_charity_donation_volunteer_btn_text') != ''){ ?>
            <p class="home-btn mb-md-0 text-center text-md-left"><a href="<?php echo esc_url(get_theme_mod('ngo_charity_donation_volunteer_btn_link','')); ?>"><?php echo esc_html(get_theme_mod('ngo_charity_donation_volunteer_btn_text','')); ?></a></p>
          <?php }?>
        </div>
        <div class="col-lg-8 col-md-8 col-sm-8 align-self-center">
          <div class="row">

            <?php $volunteer = get_theme_mod('ngo_charity_donation_volunteer_increament');

            for ($i=1; $i <= $volunteer; $i++) { ?>

              <div class="col-lg-4 col-md-4 col-sm-4">
                <div class="volunteer-box mb-3">
                  <div class="volunteer-inner-box text-center text-md-left">
                    <?php if( get_theme_mod('ngo_charity_donation_volunteer_box_icon'.$i) != '' ){ ?>
                      <i class="<?php echo esc_html(get_theme_mod('ngo_charity_donation_volunteer_box_icon'.$i)); ?> mb-3 mt-5"></i>
                    <?php }?>
                    <?php if( get_theme_mod('ngo_charity_donation_volunteer_box_number'.$i) != '' ){ ?>
                      <p><?php echo esc_html(get_theme_mod('ngo_charity_donation_volunteer_box_number'.$i)); ?></p>
                    <?php }?>
                    <?php if( get_theme_mod('ngo_charity_donation_volunteer_box_title'.$i) != '' ){ ?>
                      <h4><?php echo esc_html(get_theme_mod('ngo_charity_donation_volunteer_box_title'.$i)); ?></h4>
                    <?php }?>
                  </div>
                </div>
              </div>

            <?php } ?>

          </div>
        </div>
      </div>
    </div>
  </section>
  
  <section id="causes-section" class="py-5">
    <div class="container">
      <?php if( get_theme_mod('charity_foundation_causes_section_title') != ''){ ?>
        <h2 class="text-center mb-4"><?php echo esc_html(get_theme_mod('charity_foundation_causes_section_title')); ?></h2>
      <?php }?>
      <div class="row">
        <?php 
          $charity_foundation_catData=  get_theme_mod('charity_foundation_causes_section_category');
          if($charity_foundation_catData){
          $page_query = new WP_Query(array( 'category_name' => esc_html( $charity_foundation_catData ,'charity-foundation')));?>
          <?php while( $page_query->have_posts() ) : $page_query->the_post(); ?>
            <div class="col-lg-3 col-md-6 col-sm-6">
              <div class="causes-box mb-4">
                <?php if(has_post_thumbnail()) { ?>
                  <div class="causes-img">
                    <?php the_post_thumbnail(); ?>
                  </div>
                <?php }?>
                <?php if( get_post_meta($post->ID, 'charity_foundation_raised', true) ||  get_post_meta($post->ID, 'charity_foundation_goal', true) ) {?>
                  <div class="prices-box">                    
                    <span class="mr-3">
                      <?php if( get_post_meta($post->ID, 'charity_foundation_goal', true) ) {?>
                        <span class="first-word"><?php esc_html_e('Goal','charity-foundation'); ?></span>
                        <span> <?php echo esc_html(get_woocommerce_currency_symbol()); ?><?php echo esc_html(get_post_meta($post->ID,'charity_foundation_goal',true)); ?></span>
                      <?php }?>
                    </span>
                    <span>
                      <?php if( get_post_meta($post->ID, 'charity_foundation_raised', true) ) {?>
                        <span class="first-word"><?php esc_html_e('Raised','charity-foundation'); ?></span>
                        <span> <?php echo esc_html(get_woocommerce_currency_symbol()); ?><?php echo esc_html(get_post_meta($post->ID,'charity_foundation_raised',true)); ?></span>
                      <?php }?>
                    </span>
                  </div>
                <?php }?>
                <div class="causes-content p-3">
                  <?php if( get_post_meta($post->ID, 'charity_foundation_raised', true) != '' && get_post_meta($post->ID, 'charity_foundation_goal', true) != '' ) {
                    $raised_value = get_post_meta($post->ID, 'charity_foundation_raised', true);
                    $goal_value = get_post_meta($post->ID, 'charity_foundation_goal', true);
                    $percent_value = round(($raised_value / $goal_value) * 100); ?>
                    <div class="progress_bar">
                      <div class="progress_holder">
                        <div class="progress_number"><?php echo esc_html($percent_value); echo esc_html('%', 'charity-foundation'); ?></div>
                      </div>
                      <div class="progress_bar_holder">
                        <div class="progress_bar_content" style="width: <?php echo esc_html($percent_value); echo esc_html('%', 'charity-foundation'); ?>; background:#f9c416; border-radius: 30px"  data-score="100"></div>
                      </div>
                    </div>
                  <?php }?>
                  <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                  <p><?php $excerpt = get_the_excerpt(); echo esc_html( charity_foundation_string_limit_words( $excerpt, 15)); ?></p>
                  <?php $raised_value = get_post_meta($post->ID, 'charity_foundation_raised', true);
                  $goal_value = get_post_meta($post->ID, 'charity_foundation_goal', true);
                  if ($raised_value != '' && $goal_value != ''){
                    $percent_value = round(($raised_value / $goal_value) * 100); ?>
                    <div class="causes-slider">
                      <div class="slide-inner" style="width: <?php echo esc_attr($percent_value); echo esc_html('%', 'charity-foundation'); ?>"></div>
                    </div>
                  <?php }?>
                  <div class="home-btn my-3">
                    <a class="py-2 px-4" href="<?php the_permalink(); ?>"><?php echo esc_html('DONATE NOW','charity-foundation'); ?></a>
                  </div>
                </div>
              </div>
            </div>
          <?php endwhile;
          wp_reset_postdata();
        } ?>
      </div>
    </div>
  </section>
</main>

<?php get_footer(); ?>