<?php
/* ==========================================================
  Counter
=========================================================== */
if ( !function_exists('confin_funfact_function')) {
  function confin_funfact_function( $atts, $content = NULL ) {

    extract($atts);

    $e_uniqid       = uniqid();
    $inline_style   = '';
    if ( $title_size || $title_color  ) {
      $inline_style .= '.fun-fact-'.$e_uniqid .'.fun-fact-section .funfact-grids .grid p {';
      $inline_style .= ( $title_size ) ? 'font-size:'.confin_core_check_px($title_size) .';' : '';
      $inline_style .= ( $title_color ) ? 'color:'. $title_color .';' : '';
      $inline_style .= '}';
    }
    if ( $number_size || $number_color  ) {
      $inline_style .= '.fun-fact-'.$e_uniqid .'.fun-fact-section .funfact-grids .grid h3 {';
      $inline_style .= ( $number_size ) ? 'font-size:'.confin_core_check_px( $number_size) .';' : '';
      $inline_style .= ( $number_color ) ? 'color:'. $number_color .';' : '';
      $inline_style .= '}';
    }
    if ( $icon_size || $icon_color  ) {
      $inline_style .= '.fun-fact-'.$e_uniqid .'.fun-fact-section .funfact-grids .grid .icon i:before {';
      $inline_style .= ( $icon_size ) ? 'font-size:'.confin_core_check_px( $icon_size) .';' : '';
      $inline_style .= ( $icon_color ) ? 'color:'. $icon_color .';' : '';
      $inline_style .= '}';
    }
     // add inline style
    add_inline_style( $inline_style );
    $styled_class  = ' fun-fact-'.$e_uniqid.' ';
    $funfact_items = ( $funfact_items ) ? (array) $funfact_items : array();
    ob_start(); ?>
  <div class="fun-fact-section <?php echo esc_attr(  $class.$styled_class ) ?>">
    <div class="funfact-grids">
        <?php
        foreach ( $funfact_items as $key => $funfact_item ) {
          if ( $funfact_item->number ||  $funfact_item->title ) { ?>
          <div class="grid">
              <div>
                  <span class="icon">
                    <i class="<?php echo esc_attr( $funfact_item->icon ); ?>"></i>
                  </span>
                  <h3>
                    <span class="odometer" data-count="<?php echo esc_html( $funfact_item->number ) ?>"><?php echo esc_html__( '00','confin-core' ); ?>
                    </span>
                    <?php if ( $funfact_item->percent) {
                     echo esc_html( $funfact_item->percent );
                    } ?>
                  </h3>
              </div>
              <p><?php echo esc_html( $funfact_item->title ); ?></p>
          </div>
        <?php } } ?>
    </div>
  </div>
   <?php return ob_get_clean();
  }
}
add_shortcode( 'reg_funfact', 'confin_funfact_function' );
