<?php
/**
 * Counter section
 *
 * This is the template for the content of counter section
 *
 * @package Theme Palace
 * @subpackage Raise Charity Pro
 * @since Raise Charity Pro 1.0.0
 */
if ( ! function_exists( 'raise_charity_pro_add_counter_section' ) ) :
    /**
    * Add counter section
    *
    *@since Raise Charity Pro 1.0.0
    */
    function raise_charity_pro_add_counter_section() {
        $options = raise_charity_pro_get_theme_options();
        // Check if counter is enabled on frontpage
        $counter_enable = apply_filters( 'raise_charity_pro_section_status', true, 'counter_section_enable' );

        if ( true !== $counter_enable ) {
            return false;
        }

        // Render counter section now.
        raise_charity_pro_render_counter_section();
    }
endif;

if ( ! function_exists( 'raise_charity_pro_render_counter_section' ) ) :
  /**
   * Start counter section
   *
   * @return string counter content
   * @since Raise Charity Pro 1.0.0
   *
   */
   function raise_charity_pro_render_counter_section() {
        $options = raise_charity_pro_get_theme_options();
        $counter_column = ! empty( $options['counter_column'] ) ? $options['counter_column'] : 'col-4';
        $image = !empty( $options['counter_image'] ) ? $options['counter_image'] : '';
      
        ?>
        <div id="raise_charity_pro_counter_section">
          <div id="counter-section" class="relative page-section" style="background-image: url('<?php echo esc_url( $image ); ?>');">
          <div class="overlay"></div>
          <div class="wrapper">
          <?php if ( is_customize_preview()):
            raise_charity_pro_section_tooltip( 'counter-section' );
            endif; ?>
            <div class="<?php echo esc_attr( $counter_column ); ?> clear">

            <?php for ( $i = 1; $i <= $options['counter_count']; $i++){
              $icon    = isset($options['counter_icon_'.$i]) ? $options['counter_icon_'.$i] : 'fa-handshake-o';
             ?>

              <article>
                <div class="counter-item">
                  <span class="counter-icon"><i class="fa <?php echo esc_attr( $icon ) ; ?>"></i></span>
                  <?php if( !empty( $options['counter_value_' . $i] ) && !empty( $options['counter_label_' . $i] ) ): ?>
                  <h2 class="counter-value"><?php echo esc_html( $options['counter_value_' . $i] ); ?></h2>
                  <h3 class="counter-title"><?php echo esc_html( $options['counter_label_' . $i] ); ?></h3>
                <?php endif; ?>
                </div><!-- .counter-item -->
              </article>

              <?php } ?>
            </div><!-- .col-4 -->
          </div><!-- .wrapper -->
        </div><!-- #counter-section -->
        </div>
        
            
    <?php }
endif;