<?php
$restaurants = $this->restaurants;
?>

<?php if( count( $restaurants ) > 0 ) { ?>
<table class="restaurant-grid">
	<tr>
		<th width="15%">
			Restaurant
		</th>
		<th width="10%">
			Phone
		</th>
		<th width="5%">
			Orders
		</th>
		<th width="20%">
			Hours
		</th>
		<th width="10%">
			Status
		</th>
		<th width="150"></th>
		<th width="90"></th>
		<th width="250"></th>
		<th width="50"></th>
	</tr>
<?php foreach( $restaurants as $restaurant ) {

	$permission = c::admin()->permission()->check(['global', 'restaurants-all', 'restaurants-crud','restaurant-'.$restaurant->id_restaurant.'-all','restaurant-'.$restaurant->id_restaurant.'-edit']);

	$active = ( !$restaurant->active ) ? 'inactive' : '';
	?>
	<tr class="<?php echo $active; ?> <?php if( $restaurant->deliveryItSelf() ){ echo 'deliverThemSelves"'; } ?>">
		<td>
			<?php echo $restaurant->name; ?>
			<?php if( !$restaurant->active ){
				echo '<br/> INACTIVE';
				} ?>
		</td>
		<td>
			<?php echo $restaurant->phone(); ?>
		</td>
		<td>
			<?php echo $restaurant->totalOrders(); ?>
		</td>
		<td>
			<strong><?php echo $restaurant->timezone; ?></strong>
			<br />
			<?php echo $restaurant->closed_message(); ?>
		</td>
		<td>
			<?php if( $restaurant->open() ){ ?>
				<span class="label label-green">Open</span>
			<?php } else { ?>
				<span class="label label-gray">Closed</span>
			<?php } ?>
		</td>
		<td>
			<?php
				if( $restaurant->open_for_business ){
					$status = 'close';
					$label = 'Force close';
					$color = 'blue';
				} else {
					$status = 'open';
					$label = 'Remove "force close"';
					$color = 'red';
				}
			?>
			<?php if( $permission ) { ?>
			<input type="text" maxlength="44" style="width:140px;" placeholder="Force close tagline" value="<?php echo $restaurant->force_close_tagline; ?>" name="force_close_tagline" id="force_close_tagline-<?php echo $restaurant->id_restaurant; ?>" />
			<button class="btn btn-<?php echo $color; ?>" onclick="community.quickClose( <?php echo $restaurant->id_restaurant; ?>, '<?php echo $status; ?>' )"><?php echo $label; ?></button>
			<?php } ?>
		</td>
		<td>
			<?php if( $permission ) { ?>
			<a class="btn btn-black" data-toggle="modal" href= "#modal-hour_override" onclick="community.holidays( <?php echo $restaurant->id_restaurant; ?> )">Holidays</a>
			<?php } ?>
		</td>
		<td>
			<?php if (c::admin()->permission()->check(['global','drivers-assign', 'drivers-all'])) { ?>
				<a href="/drivers/assign/restaurant/<?php echo $restaurant->id_restaurant; ?>">Assign drivers only to this restaurant</a>
			<?php } ?>
		</td>
		<td>
			<?php if( $permission ){ ?>
				<a class="btn btn-green" href="/restaurants/<?php echo $restaurant->id_restaurant; ?>"><strong>Edit</strong></a>
			<?php } ?>
		</td>
	</tr>
<?php } ?>
</table>
<?php } else {
	echo 'There are no restaurants.';
} ?>