<?php



//Déclaration d'un item de menu dans le menu principal
function dashboard_menu(&$menuItems){
	global $myUser;
	if(!$myUser->can('dashboard','read')) return;
	$menuItems[] = array(
		'sort'=>3,
		'url'=>'index.php?module=dashboard',
		'label'=>'Dashboard',
		'icon'=> 'far fa-object-ungroup',
		'color'=> '#273c75'
	);
}

//Cette fonction va generer une page quand on clique sur Dashboard dans menu
function dashboard_page(){
	global $_;
	if(!isset($_['module']) || $_['module'] !='dashboard') return;
	$page = !isset($_['page']) ? 'list.dashboard' : $_['page'];
	$page = str_replace('..','',$page);
	$file = __DIR__.SLASH.'page.'.$page.'.php';
	if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
	
	require_once($file);
}

//Fonction executée lors de l'activation du plugin
function dashboard_install($id){
	if($id != 'fr.core.dashboard') return;
	Entity::install(__DIR__);	
}

//Fonction executée lors de la désactivation du plugin
function dashboard_uninstall($id){
	if($id != 'fr.core.dashboard') return;
	Entity::uninstall(__DIR__);
}

//Déclaration des sections de droits du plugin
Right::register('dashboard',array('label'=>'Gestion des droits sur le plugin Dashboard'));


//cette fonction comprends toutes les actions du plugin qui ne nécessitent pas de vue html
function dashboard_action(){
	require_once(__DIR__.SLASH.'action.php');
}
//Déclaration du menu de réglages
function dashboard_menu_setting(&$settingMenu){
	global $myUser;
	
	if(!$myUser->can('dashboard','configure')) return;
	$settingMenu[]= array(
		'sort' =>1,
		'url' => 'setting.php?section=global.dashboard',
		'icon' => 'fas fa-angle-right',
		'label' => 'Dashboard'
	);
}

//Déclaration des pages de réglages
function dashboard_content_setting(){
	global $_;
	if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
		require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
}


require_once(__DIR__.SLASH.'action.php');


//Déclaration des settings de base
//Types possibles : voir FieldType.class.php. Un simple string définit une catégorie.
Configuration::setting('dashboard',array(
    "Général",
    //'dashboard_enable' => array("label"=>"Activer","type"=>"boolean"),
));
  
function dashboard_application_bottom(){
?>
 <template id="dashboard-widget-template">
        <div class="dashboard-widget" data-id="{{id}}">
        	<div class="dashboard-widget-header">
        		<div class="widget-header-icon"><i class="fas fa-question"></i></div>
        		<div class="widget-header-title"></div>
        		<ul class="widget-header-options"></ul>
        	</div>
        	<div class="dashboard-widget-content"></div>
        	<div class="dashboard-widget-resize"><i class="fas fa-chevron-right"></i></div>
    	</div>
 </template>
   <?php
}



//Déclation des assets



Plugin::addCss("/css/main.css"); 
Plugin::addJs("/js/main.js"); 
Plugin::addCss("/css/component.css"); 
Plugin::addJs("/js/dashboard.js"); 
Plugin::addJs("/js/component.js"); 

//Mapping hook / fonctions
Plugin::addHook("install", "dashboard_install");
Plugin::addHook("uninstall", "dashboard_uninstall"); 
Plugin::addHook("menu_main", "dashboard_menu"); 
Plugin::addHook("page", "dashboard_page"); 
Plugin::addHook("menu_setting", "dashboard_menu_setting");
Plugin::addHook("content_setting", "dashboard_content_setting");
Plugin::addHook("application_bottom", "dashboard_application_bottom");
?>