<div class="pjScheduleWrap">
	<?php
	$url_create = 'javascript:void(0);';
	if (pjAuth::factory('pjAdminBookings', 'pjActionCreate')->hasAccess()) {
		$url_create = $_SERVER['PHP_SELF'].'?controller=pjAdminBookings&action=pjActionCreate';	
	}
	$action = $controller->_get->toString('action');

	if(isset($tpl['avail_arr'][$date]))
	{
	    if(isset($tpl['avail_arr'][$date]['avail']) && $tpl['avail_arr'][$date]['avail'] == true)
	    {
	        if(!isset($tpl['t_arr'][$date]['is_dayoff'])){
	            if(isset($tpl['t_arr'][$date]) && is_array($tpl['t_arr'][$date]))
	            {
	            	$period = $tpl['t_arr'][$date];
					if (isset($period['start_time']) && ($date > date('Y-m-d') || ($date == date('Y-m-d') && $period['start_time'] >= date('H:i'))))
					{
						?>
	        	        <!-- <div class="car-reservation-outer tooltip-demo">
	                        <a href="<?php // echo $url_create; ?>" class="car-reservation">
	                            <div class="car-reservation-inner bg-confirmed">
	                                <strong><?php // echo date($tpl['option_arr']['o_time_format'], strtotime($period['start_time']));?> - <?php // echo date($tpl['option_arr']['o_time_format'], strtotime($period['end_time']));?></strong>
	                            </div>
	                        </a>
	                    </div> -->
	        	        <?php
	    	        }
	            }
		    }
	    }else if(isset($tpl['avail_arr'][$date]['is_dayoff']) && $tpl['avail_arr'][$date]['is_dayoff'] == true){
	    }else{
	        foreach($tpl['avail_arr'][$date] as $items)
	        {  
	            if (isset($items['start_time']) && !isset($items[0])) {
		           	if (isset($items['start_time']) && ($date > date('Y-m-d') || ($date == date('Y-m-d') && $items['start_time'] >= date('H:i'))))
		           	{
						?>
		    	       	<!-- <div class="car-reservation-outer tooltip-demo">
		                    <a href="<?php // echo $url_create; ?>" class="car-reservation">
		                        <div class="car-reservation-inner bg-confirmed">
		                            <strong><?php // echo date($tpl['option_arr']['o_time_format'], strtotime($items['start_time']));?> - <?php //echo date($tpl['option_arr']['o_time_format'], strtotime($items['end_time']));?></strong> 
		                        </div>
		                    </a>
		                </div> -->
		    	        <?php
	            	}
	            }else {
	            	$tmp_booking_service_ids_arr = array();
					
	            	foreach($items as $item) {
		                if(isset($tpl['booking_arr'][$date][$item]))
		                { 
		                    $booking = $tpl['booking_arr'][$date][$item];
							
		                    if (in_array($booking['id'], $tmp_booking_service_ids_arr)) continue;
		                    if (isset($tpl['booking_schedule_arr'][$date][$booking['start_ts']]) && count($tpl['booking_schedule_arr'][$date][$booking['start_ts']]) > 1) {

								
		                    	?>
		                    	<div class="row">
		                    	<?php foreach ($tpl['booking_schedule_arr'][$date][$booking['start_ts']] as $k => $v) { 
		                    		$tmp_booking_service_ids_arr[] = $v['id'];
			                    	$status = 'bg-pending';
				                    $tooltip_text = '';
				                    $duration_text = '';
				                    if(in_array($v['booking_status'], array('confirmed')))
				                    {
				                        $status = 'bg-danger';
				                    }
				                    if(in_array($v['booking_status'], array('confirmed', 'pending')))
				                    {
				                    	$duration_text = $v['length'] . ' ' . __('minutes_lowercase', true, true);
				                    	$_arr = array();
				                    	// $_arr[] = $v['service_name'].' - '.  $duration_text.' - ' . pjCurrency::formatPrice($v['price']);
				                    	// $_arr[] = __('booking_employee', true).': '.$booking['employee_name'];
				                    	// if (!empty($booking['apprentice_name'])) {
				                    	// 	$_arr[] = __('booking_service_apprentice', true).': '.$booking['apprentice_name'];	
				                    	// }
				                        // $tooltip_text = ' data-toggle="tooltip" data-html="true" data-placement="bottom" title="'.implode('<br/>', $_arr).'"';

										$_arr[] = $booking['number_of_people'].' - '. pjCurrency::formatPrice($booking['booking_total']);
			                    	
										$tooltip_text = ' data-toggle="tooltip" data-html="true" data-placement="bottom" title="'.implode('<br/>', $_arr).'"';
				                    }
					                $url = 'javascript:void(0);';
					           		if (pjAuth::factory('pjAdminBookings', 'pjActionUpdate')->hasAccess()) {
					           			$url = $_SERVER['PHP_SELF'].'?controller=pjAdminBookings&action=pjActionUpdate&id='.$v['booking_id'];	
					           		}
		                    		?>
		                    		<div class="col-lg-6">
					           	    	<div class="car-reservation-outer tooltip-demo">
					                        <a href="<?php echo $url; ?>" class="car-reservation" <?php echo $tooltip_text;?>>
					                            <div class="car-reservation-inner <?php echo $status;?>">
					                                <!-- <p><strong><?php // echo date($tpl['option_arr']['o_time_format'], $v['start_ts']);?> - <?php // echo date($tpl['option_arr']['o_time_format'], $v['end_ts']);?></strong></p> -->
					                                <p><strong><?php echo $booking['booked_slot_id'];?> </strong></p>
					                                <?php echo pjSanitize::html($v['c_name']);?>
					                            </div>
					                        </a>
											<?php
											if ($v['start_ts'] >= time()) {
												?>
						                        <div class="clearfix">
						                            <a href="#" class="text-<?php echo $v['booking_status'] == 'confirmed' ? 'danger' : 'pending'; ?> pull-left btn-reminder" data-booking_id="<?php echo $v['booking_id'];?>" title="<?php __('send_reminder', false, true); ?>"><i class="fa fa-bell"></i></a>
						                            <?php if (($action == 'pjActionWeekly' && pjAuth::factory('pjAdminBookings', 'pjAdminSchedule_pjActionCancelServiceWeekly')->hasAccess()) || ($action == 'pjActionMonthly' && pjAuth::factory('pjAdminBookings', 'pjAdminSchedule_pjActionCancelServiceMonthly')->hasAccess())) { ?>
						                            	<a href="#" class="text-<?php echo $v['booking_status'] == 'confirmed' ? 'danger' : 'pending'; ?> pull-right btn-delete" data-id="<?php echo $v['service_id'];?>" data-booking_id="<?php echo $v['booking_id'];?>" title="<?php __('btnCancel', false, true); ?>"><i class="fa fa-trash"></i></a>
						                            <?php } ?>
						                        </div><!-- /.clearfix -->
						                        <?php 
											}
											?>
					                    </div>
					            	</div>
		                    	<?php } ?>
		                    	</div>
		                    	<?php 
		                    } else {
		                    	$tmp_booking_service_ids_arr[] = $booking['id'];
			                    $status = 'bg-pending';
			                    $tooltip_text = '';
			                    $duration_text = '';
			                    if(in_array($booking['booking_status'], array('confirmed')))
			                    {
			                        $status = 'bg-danger';
			                    }
			                    if(in_array($booking['booking_status'], array('confirmed', 'pending')))
			                    {
									//print_r($booking);
			                    	$duration_text = $booking['length'] . ' ' . __('minutes_lowercase', true, true);
			                    	$_arr = array();
			                    	// $_arr[] = $booking['service_name'].' - '.  $duration_text.' - ' . pjCurrency::formatPrice($booking['price']);
			                    	// $_arr[] = __('booking_employee', true).': '.$booking['employee_name'];
			                    	// if (!empty($booking['apprentice_name'])) {
			                    	// 	$_arr[] = __('booking_service_apprentice', true).': '.$booking['apprentice_name'];	
			                    	// }
			                        // $tooltip_text = ' data-toggle="tooltip" data-html="true" data-placement="bottom" title="'.implode('<br/>', $_arr).'"';

									$_arr[] = $booking['number_of_people'].' - '. pjCurrency::formatPrice($booking['booking_total']);
			                    	
			                    	$tooltip_text = ' data-toggle="tooltip" data-html="true" data-placement="bottom" title="'.implode('<br/>', $_arr).'"';


			                    }
				                $url = 'javascript:void(0);';
				           		if (pjAuth::factory('pjAdminBookings', 'pjActionUpdate')->hasAccess()) {
				           			$url = $_SERVER['PHP_SELF'].'?controller=pjAdminBookings&action=pjActionUpdate&id='.$booking['booking_id'];	
				           		}
			                    ?>
			                    <div class="row">
			                    	<div class="col-xs-12">
				           	    	<div class="car-reservation-outer tooltip-demo">
				                        <a href="<?php echo $url; ?>" class="car-reservation"<?php echo $tooltip_text;?>>
				                            <div class="car-reservation-inner <?php echo $status;?>">
				                                <!-- <p><strong><?php // echo date($tpl['option_arr']['o_time_format'], $booking['start_ts']);?> - <?php // echo date($tpl['option_arr']['o_time_format'], $booking['end_ts']);?></strong></p> -->
												<p><strong><?php echo $booking['booked_slot_id'];?> </strong></p>
				                                <?php echo pjSanitize::html($booking['c_name']);?>
				                            </div>
				                        </a>
										<?php
										if ($booking['start_ts'] >= time()) {
											?>
					                        <div class="clearfix">
					                            <a href="#" class="text-<?php echo $booking['booking_status'] == 'confirmed' ? 'danger' : 'pending'; ?> pull-left btn-reminder" data-booking_id="<?php echo $booking['booking_id'];?>" title="<?php __('send_reminder', false, true); ?>"><i class="fa fa-bell"></i></a>
					                            <?php if (($action == 'pjActionWeekly' && pjAuth::factory('pjAdminBookings', 'pjAdminSchedule_pjActionCancelServiceWeekly')->hasAccess()) || ($action == 'pjActionMonthly' && pjAuth::factory('pjAdminBookings', 'pjAdminSchedule_pjActionCancelServiceMonthly')->hasAccess())) { ?>
					                            	<a href="#" class="text-<?php echo $booking['booking_status'] == 'confirmed' ? 'danger' : 'pending'; ?> pull-right btn-delete" data-id="<?php echo $booking['service_id'];?>" data-booking_id="<?php echo $booking['booking_id'];?>" title="<?php __('btnCancel', false, true); ?>"><i class="fa fa-trash"></i></a>
					                            <?php } ?>
					                        </div><!-- /.clearfix -->
					                        <?php 
										}
										?>
				                    </div>
					            	</div>
					            </div>
			                    <?php
			                }
		                }
		            }
	            }
	        }
	    }
	}
	?>
</div>