<?php
if ( ! get_theme_mod( 'construktly_enable_counter_section', false ) ) {
	return;
}

$section_content = array();
$default_color   = construktly_get_default_color();

$section_content['background_color'] = get_theme_mod( 'construktly_counter_background_color', $default_color['primary'] );
$section_content['count']            = get_theme_mod( 'construktly_counter_count', 4 );

$section_content = apply_filters( 'construktly_counter_section_content', $section_content );

construktly_render_counter_section( $section_content );

/**
 * Render Counter Section
 */
function construktly_render_counter_section( $section_content ) {
	$style_attr = '';
	if ( ! empty( $section_content['background_color'] ) ) {
		$style_attr = 'background-color: ' . $section_content['background_color'] . ';';
	}
	?>
	<section id="construktly_counter_section" class="construktly-frontpage-section construktly-counter-section counter-style-two" >
		<?php
		if ( is_customize_preview() ) :
			construktly_section_link( 'construktly_counter_section' );
		endif;
		?>
		<div class="ascendoor-outer-wrapper" style="<?php echo esc_attr( $style_attr ); ?>;">
			<div class="ascendoor-wrapper">
				<div class="construktly-counter-details">
					<div class="construktly-section-body">
						<div class="construktly-counter-wrapper">
							<?php
							for ( $i = 1; $i <= $section_content['count']; $i++ ) {
								$icon         = get_theme_mod( 'construktly_counter_icon_' . $i );
								$label        = get_theme_mod( 'construktly_counter_label_' . $i );
								$value        = get_theme_mod( 'construktly_counter_value_' . $i );
								$value_suffix = get_theme_mod( 'construktly_counter_value_suffix_' . $i );
								?>
								<div class="construktly-counter-single">
									<?php if ( ! empty( $icon ) ) { ?>
									<div class="construktly-counter-img">
										<img src="<?php echo esc_url( $icon ); ?>" alt="<?php echo esc_attr( $label ); ?>">
									</div>
									<?php } ?>
									<div class="construktly-counter-txt">
										<h3>
											<span class="count" data-count="<?php echo esc_attr( $value ); ?>"></span><?php echo esc_html( $value_suffix ); ?>
										</h3>
										<p><?php echo esc_html( $label ); ?></p>
									</div>
								</div>
								<?php
							}
							?>
						</div>      
					</div>
				</div>
			</div>
		</div>
	</section>
	<?php
}
