<!DOCTYPE html>
<html lang="en">
<head>
	<?php
	$partial = new Partial('head');
	$partial->render();
	?>
	<title><?php echo $TITLE ?></title>
</head>
<body class="no-transitions">
	<div class="row no-gutters main">
		<div class="col-md-3 d-sm-none"></div>
		<div class="col-md-3 nav-container">
			<div class="nav">
				<div class="nav-item is-active">
					<a href="./"><i class="fa fa-home"></i><span><?php echo $LANG['m_home']?></span></a>
				</div>
				<div class="nav-item">
					<a href="dashboard"><i class="fa fa-tachometer" aria-hidden="true"></i><span><?php echo $LANG['m_dashboard']?></span></a>
				</div>
				<div class="nav-item">
					<a href="setting"><i class="fa fa-wrench" aria-hidden="true"></i></i><span><?php echo $LANG['m_settings']?></span></a>
				</div>
				<div class="nav-item">
					<a href="automation"><i class="fa fa-calendar-o" aria-hidden="true"></i><span><?php echo $LANG['m_automatization']?></span></a>
				</div>
				<div class="nav-item">
					<a href="scene"><i class="fa fa-terminal" aria-hidden="true"></i><span><?php echo $LANG['m_scenes']?></span></a>
				</div>
			</div>
		</div>
		
		<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.bundle.min.js"></script>
		
		<div class="col-md-9 main-body">
			<div class="label m-1">
				<?php 
				$usersAtHome = '';
				foreach ($USERS as $user) {
					if ($user['at_home'] == 'true') {
						$usersAtHome .= $user['username'] . ' ';
					}
				}
				if ($usersAtHome != "") {
					echo 'doma jsou:' . $usersAtHome; 	
				}
				?>
			</div>
			<select class="select m-1" name="room">
				<option value="all">All</option>
				<?php foreach ($ROOMS as $key => $room) {
					if ($room['device_count'] > 0) { ?>
						<option value="<?php echo $room['room_id']?>"><?php echo $room['name'] ?></option>
					<?php } ?>
				<?php } ?>
			</select>
			<div class="row no-gutters">
				<?php foreach ($DATA as $roomId => $room) { ?>					
					<?php foreach ($room['devices'] as $deviceId => $device) { ?>				
						<?php foreach ($device['subDevices'] as $subDeviceKey => $subDevice) {
							//BUTTON
							$partialDeviceButton = new Partial('deviceButton');
							$partialDeviceButton->prepare('roomid',$roomId);
							$partialDeviceButton->prepare('subdeviceid',$subDeviceKey);
							$partialDeviceButton->prepare('subdevice',$subDevice);
							$partialDeviceButton->prepare('deviceid',$deviceId);
							$partialDeviceButton->prepare('device',$device);
							
							$partialDeviceButton->render();
							
							//DETAIL
							$partialDetail = new Partial('deviceDetail');
							$partialDetail->prepare('subdeviceid',$subDeviceKey);
							$partialDetail->prepare('subdevice',$subDevice);
							$partialDetail->prepare('device',$device);
							$partialDetail->prepare('lang',$LANG);
							
							$partialDetail->render();
							
							//SETTING
							$partialEdit = new Partial('deviceEdit');
							$partialEdit->prepare('deviceid',$deviceId);
							$partialEdit->prepare('subdevice',$subDevice);
							$partialEdit->prepare('device',$device);
							$partialEdit->prepare('users',$USERS);
							$partialEdit->prepare('rooms',$ROOMS);
							$partialEdit->prepare('lang',$LANG);
							
							$partialEdit->render();
						} 
					}
				} ?>
			</div>
		</div>
	</div>
	<?php
	$partial = new Partial('footer');
	$partial->render();
	?>
</body>
</html>