<?php 
$shift = $this->shift;
?>
<div class="row-fluid">
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span12">
						<form>
							<div class="row-fluid">
								<div class="span12">
									<div class="span4">
										<strong>Community:</strong>
									</div>
									<div class="span7">
										<?php echo $shift->community()->name; ?>
									</div>
								</div>
							</div>
							<div class="row-fluid">
								<div class="span12">
									<div class="span4">
										<strong>Date:</strong>
									</div>
									<div class="span7">
										<input type="hidden" name="form-id_community_shift" id="form-id_community_shift" value="<?php echo $shift->id_community_shift ?>"/>
										<?php echo $shift->dateStart()->format( 'm/d/Y' ); ?>
									</div>
								</div>
							</div>
							<div class="row-fluid">
								<div class="span12">
									<div class="span4">
										<strong>Timezone</strong>
									</div>
									<div class="span7">
										<strong><?php echo $shift->timezone(); ?></strong>
									</div>
								</div>
							</div>
							<?php if( $shift->id_community_shift_father || $shift->recurring > 0  ){ ?>
								<div class="row-fluid">
									<div class="span12">
										<div class="span4">
											<strong>Repeat</strong>
										</div>
										<div class="span7">
											Repeat every <?php echo $shift->dateStart()->format( 'l' ); ?>
										</div>
									</div>
								</div>
							<?php } ?>
							<div class="row-fluid">
								<div class="span12">
									<div class="span4">
										<strong>Hours</strong>
									</div>
									<div class="span7">
										<?php if( $shift->id_community_shift_father || $shift->recurring > 0  ){ ?>
											<?php echo $shift->startEndToString(); ?> (<?php echo $shift->timezoneAbbr(); ?>)
										<?php } else { ?>
											<input type="text" value="<?php echo $shift->startEndToString(); ?>" name="form-hours" id="form-hours"/> 
										<?php } ?>
										<br/><br/>
									</div>
								</div>
							</div>
							<?php
								$_drivers = $shift->getDrivers();
								$hasDriver = false;
								$drivers = [];
								foreach( $_drivers as $driver ){
									$hasDriver = true;
									$drivers[] = $driver->name;
								}
								if( $hasDriver ){
									$drivers = join( ', ', $drivers ); 	
								} 
							?>
							<?php if( $hasDriver ) { ?>
							<div class="row-fluid">
								<div class="span12">
									<div class="span4">
										<strong>Drivers assigned to this shift</strong>
									</div>
									<div class="span7">
										<?php echo $drivers; ?>
										<br/><br/>
									</div>
								</div>
							</div>
							<?php } ?>
							<?php 
								$preferences = $shift->getAdminPreferences();
								$hasDriver = false;
								foreach( $preferences as $preference ) { 
									if( $preference->ranking > 0 ){
										$hasDriver = true;
									}
								}
								if( $hasDriver ){
									?>
								<div class="row-fluid">
									<div class="span12">
										<div class="span4">
											<strong>Drivers that want to work at this shift</strong>
										</div>
										<div class="span7">
											<?php 
											$commas = '';
											foreach( $preferences as $preference ) { 
												if( $preference->ranking > 0 ){
													echo $commas . $preference->admin()->name . ' (' . $preference->ranking . ')';
													$commas = ', ';	
												}
											} ?>
											<br/><br/>
										</div>
									</div>
								</div>
									<?php
								}
							?>
							<div class="row-fluid">
								<div class="row-fluid">
									<div class="span12">
										<br/>
									</div>
								</div>
								<div class="row-fluid">
									<div class="span6">

										<?php if( $shift->id_community_shift_father ){ ?>
											<button type="button" onclick="shift.community.remove();" class="btn btn-red"><i class="icon-trash"></i> Remove </button> 
											&nbsp;<button type="button" onclick="shift.community.removeRecurring();" class="btn btn-red"><i class="icon-trash"></i> Remove recurrence</button> 
										<?php } else if( $shift->recurring > 0 ){ ?>
											<button type="button" onclick="shift.community.removeRecurringFather();" class="btn btn-red"><i class="icon-trash"></i> Remove </button> 
										<?php } else { ?>
											<button type="button" onclick="shift.community.edit();" class="btn btn-green"><i class="icon-save"></i> Save </button>
											&nbsp;<button type="button" onclick="shift.community.remove();" class="btn btn-red"><i class="icon-trash"></i> Remove </button> 
										<?php } ?>
									</div>
								</div>
							</div>
						</form>
			</div>
		</div>
	</div>
</div>