<?php

	 $bookingFields =  get_field('um_fields','options');
	 $hasTerms = get_field('terms','options');
	 $hasCheckInOut = get_field('check_in/out','options');
	 $calulateTotal = get_field('calculate_price','options');
 	 $post_ID = $_POST['post_id'];
 ?>	
	 
<section class="bookingForm">
	<div class="row um_post_id" data-um_post_id = "<?php echo $post_ID; ?>">
				
	<?php if($bookingFields): ?>
		<?php foreach($bookingFields as $field): ?>
			
		
			<?php 
				$type = $field['field_type'];
				$col_md_class = "col-md-4";
				$mendatory = $field['mendatory'];
				$isMendatory = 'false';
				$multiRow = '';
				$field_unique_name = "um_".sanitize_text_field(remove_accents(preg_replace('/\s+/', '_', $field['field_name'])));
				
				if($mendatory){
					$isMendatory = 'true';
				}
				if($type == "area"){
					$col_md_class = "col-md-12";
				}
				if($type == 'radio' || $type == 'check' ){
					$multiRow = 'multiRow';
				}
			 ?>
			
			<div class="<?php echo $col_md_class; ?>">
				
				<div  data-um_mendatory="<?php echo $isMendatory; ?>" data-um_type="<?php echo $type; ?>" class="formInput <?php echo $multiRow; ?>">
					<label for="<?php echo $field_unique_name; ?>"><?php echo $field['field_name']; ?></label>
					<i data-um_icon = "<?php echo $field['icon']; ?>" class="fa <?php echo $field['icon']; ?>"></i>
					
					<?php if($type == 'text' || $type == "email" || $type == "tel"): ?>
						
						<input type="<?php echo $type; ?>"  data-unique_id = "<?php echo $field['unique_id']; ?>" name="<?php echo $field_unique_name; ?>" value="" id=""/>
					
					<?php elseif($type == "number"): ?>
	
	
						<?php if(get_field('advanced_calculation','options')): ?>
							
							<?php if (in_array('adults', get_field('advanced_calculation','options')) || in_array('children', get_field('advanced_calculation','options')) ): ?>	
								
								<?php if(get_field('adult_filed_id','options') == $field['unique_id'] && in_array('adults', get_field('advanced_calculation','options'))): ?>			
								
										<input  data-unique_id ="<?php echo $field['unique_id']; ?>" type="number" id="um_adults" name="<?php echo $field_unique_name; ?>" min="0" max="<?php the_field('max_adults',$post_ID); ?>" id=""/>
								
								<?php elseif(get_field('children_field_id','options') == $field['unique_id'] && in_array('children', get_field('advanced_calculation','options'))): ?>
								
										<input  data-unique_id ="<?php echo $field['unique_id']; ?>" type="number" id="um_children" name="<?php echo $field_unique_name; ?>" min="0" max="<?php the_field('max_children',$post_ID); ?>" id=""/>
								<?php else: ?>					
									<input  type="number" name="<?php echo $field_unique_name; ?>" min="0" id=""/>
								<?php endif; ?>
								
							<?php else: ?>
									<input  type="number" name="<?php echo $field_unique_name; ?>" min="0" id=""/>
							<?php endif; ?>
						<?php else: ?>
								<input  type="number" name="<?php echo $field_unique_name; ?>" min="0" id=""/>
						<?php endif; ?>
							
													
					<?php elseif($type == "area"): ?>
					
						<textarea   name="<?php echo $field_unique_name; ?>" value=""></textarea>
					
					<?php elseif($type == "date"): ?>
					
						<input  type="text" class="um_datePicker" name="<?php echo $field_unique_name; ?>" value="" id=""/>
					
					<?php elseif($type == "drop"): ?>
					
						<?php if($field['values']):?>
							<select   class="selectpicker" data-width="100%">
								<?php foreach($field['values'] as $subValues): ?>
									<option class="<?php echo $subValues['value']; ?>" ><?php echo $subValues['value']; ?></option>																		
							<?php endforeach; ?>
							</select>	
						<?php endif; ?>	
					
					<?php elseif($type == "radio"): ?>
					
						<?php if($field['values']):?>
							<fieldset>
								<?php $checked = 'checked'; ?>
								<?php foreach($field['values'] as $subValues): ?>
									<label><input  <?php echo $checked; ?> type="radio" name="<?php echo $field_unique_name; ?>" value="<?php echo $subValues['value']; ?>"><?php echo $subValues['value']; ?></label>
									<?php $checked = ''; ?>
								<?php endforeach; ?>
							</fieldset>
						<?php endif; ?>		
					
					<?php elseif($type == "check"): ?>
					
						<?php if($field['values']):?>
							<fieldset>
								<?php foreach($field['values'] as $subValues): ?>
									<label><input  type="checkbox" name="<?php echo $field_unique_name; ?>" value="<?php echo $subValues['value']; ?>"><?php echo $subValues['value']; ?></label>
								<?php endforeach; ?>
							</fieldset>
						<?php endif; ?>	
					
					<?php endif; ?>
				</div>
			
			</div>
	
	<?php endforeach; ?>
	<?php endif; ?>
	
	<div class="clearfix"></div>
		
	<!-- Calendar  -->
	<?php if($hasCheckInOut): ?>
		<div class="col-md-4">
			<div data-um_mendatory="true" class="formInput um_datePicker">
				<label for="country"><?php _e('From','um_lang'); ?></label>
				<i class="fa fa-user"></i>
				<input  id="um_date_start" type="text" class="datepicker" name="um_arival" value="" id="um_arival"/>
			</div>	
		</div>
		<div  class="col-md-4">
			<div data-um_mendatory="true" class="formInput um_datePicker">
				<label for="country"><?php _e('To','um_lang'); ?></label>
				<i class="fa fa-user"></i>
				<input  id="um_date_end" type="text" class="datepicker" name="um_departure" value="" id="um_departure"/>
			</div>
		</div>
	<?php endif; ?>
	
	<div class="clearfix"></div>
	
	<!--  Terms  -->
	<?php if($hasTerms):  ?>
			<div class="col-md-12">
				<div data-um_mendatory="true" class="termsWrapper formInput">	
					
					<label>
						<input data-um_type="um_terms" type="checkbox" value="" id="termsVal"/>
						<?php the_field('terms_title','options'); ?>
					</label>
					<a href="#" class="terms-toggle" data-toggle="collapse" data-target="#terms">	
						<i class="fa fa-chevron-circle-down fa-lg"></i>
					</a>
				</div>
				<div id="terms" class="">
					<?php the_field('terms_text','options'); ?>
				</div>
			</div>
	<?php endif; ?>	
			
	<!-- Total  -->
	<?php if($hasCheckInOut): ?>	
		<?php if($calulateTotal): ?>	
				<div class="col-md-8">
					<div class="total">
						<i class="fa fa-user"></i>
						<div class="bookTotal">
							<label class=".title"><?php _e('Total:','um_lang'); ?></label>
							<div class="bookResult">
								
								<?php if(get_field('advanced_calculation','options')): ?>
									<?php if (in_array('adults', get_field('advanced_calculation','options')) ):?>
										<span class="period"> <span id="um_calc_adult">0</span> <?php _e('Adults','um_lang'); ?></span>
									<?php endif; ?>
									<?php if(in_array('children', get_field('advanced_calculation','options')) ): ?>	
										<span class="period"> <span id="um_calc_children">0</span> <?php _e('Children','um_lang'); ?></span>
									<?php endif; ?>
								<?php endif; ?>
								
								<span class="period"> <span id="um_calc_period">0</span> <?php _e('nights','um_lang'); ?></span>
								<strong class="price"><span id="um_calc_price" data-um_children_price="<?php the_field('children_price', $post_ID); ?>" data-um_price="<?php  the_field('price', $post_ID); ?>">0</span> <?php the_field('default_currency','options'); ?></strong>
							</div>
						</div>
					</div>
				</div>
		<?php endif; ?>	
	<?php endif; ?>	
		
		
	<!-- Book Button -->
	<div class="col-md-4">
		<div class="">
			<button class="btn submitBtn um_bookBtn default"><?php _e('Book Now!','um_lang'); ?></button>
		</div>
	</div>		
	</div>	
	</section>	