<?php 
global $myUser,$conf; 
require_once('Dashboard.class.php');
require_once('DashboardWidget.class.php');

$dashboards = Dashboard::loadAll(array('user'=>$myUser->login));



?>
<div class="dashboard-container" style="<?php echo count($dashboards)==1 ? 'padding-left: 0px;' : ''; ?>">
	<?php if($myUser->connected()): ?>
		<ul id="dashboardView" class="<?php echo count($dashboards)>1?'':'hidden' ?>" >
			<li class="dashboardView-title">DASH</li>
			<?php 
			
			if(count($dashboards)==0){
				$defaultDash = Dashboard::provide();
				$defaultDash->user = $myUser->login;
				$defaultDash->label = 'Général';
				$defaultDash->icon = 'far fa-bookmark';
				$defaultDash->default = true;
				$defaultDash->save();
				$dashboards[] = $defaultDash;

				foreach(array('profile','clock','log') as $i=>$widget){
					$item = new DashboardWidget();
					$item->model = $widget;
					$item->position = $i;
					$item->dashboard = $defaultDash->id;
					$item->save();
				}
				
			}
			foreach($dashboards as $dashboard): ?>
				<li class="dashboard-item" <?php echo $dashboard->default?'data-selected="1"':''; ?> data-id="<?php echo $dashboard->id; ?>"  title="<?php echo $dashboard->label; ?>"><span><?php echo $dashboard->label; ?></span><div><i class="fa <?php echo $dashboard->icon; ?>"></i></div></li>
			<?php endforeach; ?>
		</ul>
		<div class="clear"></div>


		<ul class="dashboard-widget-menu">
		<li data-toggle="modal" data-target="#addWidgetModal">
			<div title="Ajouter un widget"><i class="fas fa-plus"></i> <span>WIDGET</span></div>
		</li>
	</ul>
	

	<div class="row" id="dashboard">
		<!-- MODEL WIDGET -->
		<div class="col-md-4 widget" data-id="" style="display:none" >
			<div class="widget_window">
				<div class="widget_header">
					<i class="fa fa-caret"></i> <span></span>
					<ul class="widget_options"></ul>
				</div>
				<div class="widget_content"></div>
				<div class="widget_footer"></div>
			</div>
		</div>

	</div>
		
	<?php else: ?>
		<div class="well"><h3>Bienvenue !</h3>
			<blockquote>
				<p>Merci de vous connecter pour acceder à l'ensemble des fonctionnalités.<br/> Vous pouvez vous connecter à tout moment via
					le  formulaire de connexion en haut à droite du programme</p>
					<small>HackBuddy</small>
				</blockquote>
			</div>
		<?php endif; ?>

		
		<!-- Add wiget modal -->
		<div class="modal fade" id="addWidgetModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		      <div class="modal-header">
		        <h5 class="modal-title" id="exampleModalLabel">Ajout d'un widget</h5>
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
		          <span aria-hidden="true">&times;</span>
		        </button>
		      </div>
		      <div class="modal-body">
		       		<label for="widgetList">Sélectionnez le widget que vous souhaitez ajouter</label>
						<div class="clearFix">
							<?php
								$models = array();
								Plugin::callHook('widget',array(&$models));
							?>
							<select id="widgetList" class="left" size="10">
								<option calue=""> - </option>
								<?php
								foreach($models as $model): ?>
								<option data-description="<?php echo $model->description; ?>" data-background="<?php echo $model->background; ?>" data-icon="<?php echo $model->icon; ?>" value="<?php echo $model->model; ?>"><?php echo $model->title; ?></option>
							<?php endforeach; ?>
						</select>
						<div class="widgetDescription hidden">
							<h1>
								<i class=''></i> <span></span>
							</h1>
								<p></p> 
								<span class="text-muted">Couleur: </span>
								<div class='widgetColor' >
									<small style='background-color:"+option.background+"'></small><span></span>
								</div>
						</div>
					</div>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
				<button type="button" class="btn btn-primary" onclick="dashboard_dashboardwidget_add();">Ajouter</button>
		      </div>
		    </div>
		  </div>
		</div>


		

	<!-- Configure wiget modal -->
	<div class="modal fade" id="configureWidgetModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
	  <div class="modal-dialog" role="document">
	    <div class="modal-content">
	      <div class="modal-header">
	        <h5 class="modal-title" id="exampleModalLabel">Configuration d'un widget</h5>
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
	          <span aria-hidden="true">&times;</span>
	        </button>
	      </div>
	      <div class="modal-body">
	        <div class="pluginContent">
						<!-- Configuration plugin ici -->
			</div>
	      </div>
	      <div class="modal-footer">
	       	<button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
			<button type="button" class="btn btn-primary" onclick="dashboard_dashboardwidget_save_configuration();">Ajouter</button>
	      </div>
	    </div>
	  </div>
	</div>



	
	
</div> 