<?php

// Prevent Direct Access
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$prices_suptitle = get_theme_mod('prices_suptitle');
$prices_title = get_theme_mod('prices_title');
$section_id = get_theme_mod('prices_menu_id', 'prices');
?>

<section id="<?php echo $section_id ?>" class="padding">
	<div class="container text-center">

		<?php if( $prices_title != '' || $prices_suptitle != '' ){ ?>
		<div class="row">
			<div class="col-sm-12 title_block bottom20">
			<?php
			if( $prices_suptitle != '' ){ echo '<p class="title bottom0">'.$prices_suptitle.'</p>'; }
			if( $prices_title != '' ){ echo '<h2 class="darkcolor">'.$prices_title.'</h2>'; }
			?>
			</div>
		</div>
		<?php } ?>
		
		<?php
		$prices = new WP_Query(array(
			'post_type' => 'price',
			'posts_per_page' => 3
		));

		if( $prices -> have_posts() ){

			$count = $prices->post_count;

			if($count == 1){ $column_class = 'col-xs-12'; }
			else if($count == 2){ $column_class = 'col-sm-6'; }
			else{ $column_class = 'col-sm-4'; }

		?>
		<div class="row">

			<?php
			while( $prices -> have_posts() ){

				$prices -> the_post();

				$price_stars = rwmb_meta('price_stars');
				$price_amount = rwmb_meta('price_amount');
				$price_unit = rwmb_meta('price_unit');
				$price_duration = rwmb_meta('price_duration');
				$price_features = rwmb_meta('price_features');
				$price_button_text = rwmb_meta('price_button_text');
				$price_button_link = rwmb_meta('price_button_link');
				$price_special = rwmb_meta('price_special');
				?>
			
			<div class="<?php echo $column_class ?>">
				<div class="pricing_item top40 <?php if($price_special){ echo 'active'; } ?>">
					
					<div class="pricebox bottom25 clearfix">
					
						<?php if( get_the_title() != '' || $price_stars != 'hide' ){ ?>
						<div class="price_title">
						
							<?php if( get_the_title() != '' ){ echo '<h3 class="darkcolor bottom10">'.get_the_title().'</h3>'; } ?>
							
							<?php if( $price_stars != 'hide' ){ ?>
							<span class="ratings">
								<?php
								for($i=1; $i<=5; $i++){
									echo '<i class="fa fa-star'.($i > $price_stars ? '-o' : '').'"></i> ';
								}
								?>
							</span>
							<?php } ?>
							
						</div>
						<?php } ?>
						
						<?php if( $price_amount != '' || $price_duration != '' ){ ?>
						<div class="price darkcolor">
							<p>
								<?php
								if( $price_amount != '' ){ echo '<strong>'.$price_amount.' '.($price_unit != '' ? '<small>'.$price_unit.'</small>' : '').'</strong>'; }
								if( $price_duration != '' ){ echo ' <span class="month">'.$price_duration.'</span>'; }
								?>
							</p>
						</div>
						<?php } ?>
						
					</div>

					<?php
					if( $price_features ){
						foreach($price_features as $feature){
							echo '<p class="availability">'.$feature.'</p>';
						}
					}
					?>

					<?php if( $price_button_text != '' ){ ?>
					<a href="<?php echo $price_button_link ?>" class="button <?php echo $price_special ? 'border' : 'dark' ?> top20"><?php echo $price_button_text ?></a>
					<?php } ?>
					
				</div>
			</div>

			<?php } ?>

		</div>
		<?php
		}

		wp_reset_postdata();
		?>
		
	</div>
</section>