<?php
if ( ! empty( $this->choices )) :

	$st = $this->setting;
	$widget = $this->widget;
	foreach( $this->choices as $choice ) :

		$icon = '';
		if ( ! empty( $choice->choi_icon ))
		{
			$ic = $choice->choi_icon;
			$parts = explode( '-', $ic );
			$prefix = array_shift( $parts );
			if ( strlen( $prefix ) == 2 ){
				$icon = 'ipjck-'.$prefix.' ipjck-'.$ic;
			} else {
				$icon = 'ipjck-fa ipjck-fa-'.$ic;
			}
		}

		$statVote = $this->statData->stat_vote;
		$count    = 0;
		$percent  = 0;
		if ( ! empty( $choice->choi_count )) {
			$count   = (int)$choice->choi_count; 
			$percent = round( $count/$statVote * 100, 2 );
		}
	?>
	<style>
		<?php
		$color = $choice->choi_color;
		$style = $st->getSetting( 'result_style', 1 );

		$phpcolor = new phpColor( $color );
		$codark   = $phpcolor->darken( 10 );
		
		//Style 1
		if ( $style == 1 ) :
		?>
		#ipjck-stat-<?php echo $choice->choi_id; ?> .ipjck-stat-icon {
			color: <?php echo $color; ?>;
		}
		<?php
		endif;

		//Style 2
		if ( $style == 2 ) :
		?>
		#ipjck-stat-<?php echo $choice->choi_id; ?> .ipjck-stat-icon {
			color: <?php echo $color; ?>;
			border-color: <?php echo $color; ?>;
		}
		<?php
		endif;

		//Style 3
		if ( $style == 3 ) :
		?>
		#ipjck-stat-<?php echo $choice->choi_id; ?> .ipjck-stat-icon {
			background-color: <?php echo $color; ?>;
		}
		<?php
		endif;

		//Style 4
		if ( $style == 4 ) :
		?>
		#ipjck-stat-<?php echo $choice->choi_id; ?> .ipjck-stat-icon {
			background-color: <?php echo $color; ?>;
			border-color: #<?php echo $codark; ?>;
		}
		<?php
		endif;

		//Style 5
		if ( $style == 5 ) :
			if ( $phpcolor->isDark() ) {
				$textcolor = $phpcolor->lighten( 50 );
			} else {
				$textcolor = $phpcolor->darken( 50 );
			}
		?>
		#ipjck-stat-<?php echo $choice->choi_id; ?> .ipjck-stat-label {
			background-color: <?php echo $color; ?>;
			color: #<?php echo $textcolor; ?>;
		}
		#ipjck-stat-<?php echo $choice->choi_id; ?> .ipjck-stat-icon {
			color: #<?php echo $textcolor; ?>;
		}
		<?php
		endif;
		?>
	</style>
	<!-- start: .ipjck-stat-item -->
	<div id="ipjck-stat-<?php echo $choice->choi_id; ?>" class="ipjck-stat-item">
		<div class="ipjck-stat-label">
			<span class="ipjck-stat-icon">
				<i class="<?php echo $icon; ?>"></i>
			</span>
			<strong class="ipjck-stat-title">
				<?php echo $choice->choi_title; ?>
			</strong>
		</div>

		<div class="ipjck-stat-bar">
			<div class="ipjck-stat-bar-indicator" style="width:<?php echo $percent; ?>%;background-color:<?php echo $choice->choi_color; ?>;"></div>
			<div class="ipjck-stat-value"><?php echo $count; ?></div>
		</div>

	</div>
	<!-- end: .ipjck-stat-item -->

<?php
	endforeach;
endif;
?>