<?php
namespace JExtstore\Component\JRealtimeAnalytics\Administrator\View\Realstats;
/** 
 * @package JREALTIMEANALYTICS::REALSTATS::administrator::components::com_jrealtimeanalytics
 * @subpackage views
 * @subpackage realstats
 * @author Joomla! Extensions Store
 * @copyright (C) 2013 - Joomla! Extensions Store
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html 
 */
defined ( '_JEXEC' ) or die ( 'Restricted access' );   
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
use JExtstore\Component\JRealtimeAnalytics\Administrator\Framework\Helpers\Toolbars as ToolbarHelper;
use JExtstore\Component\JRealtimeAnalytics\Administrator\Framework\View as JRealtimeView;

/**
 * Realtime stats view
 *
 * @package JREALTIMEANALYTICS::REALSTATS::administrator::components::com_jrealtimeanalytics
 * @subpackage views
 * @subpackage realstats
 * @since 1.0
 */
class HtmlView extends JRealtimeView { 
	/**
	 * Add the page title and toolbar.
	 *
	 * @since	1.6
	 */
	protected function addDisplayToolbar() {
		ToolbarHelper::title( Text::_( 'COM_JREALTIME_REALSTATS_GRAPH_HEADER' ), 'jrealtimeanalytics' );
		ToolbarHelper::custom('cpanel.display', 'home', 'home', 'COM_JREALTIME_CPANEL', false);
	}

	/**
	 * Default inject JS APP
	 * @access public
	 * @return void
	 */
	public function display($tpl = null) {
		$componentConfig = $this->get('Config');
		
		$doc = $this->app->getDocument();
		$this->loadJQuery($doc);
		$this->loadBootstrap($doc);
		$this->loadJQVMap($doc);
		$this->loadJQFancybox($doc);
		$doc->getWebAssetManager()->addInlineScript(" 
					var jrealtimeServerStatsEndpoint = '" . Uri::root() . 'administrator/index.php?option=com_jrealtimeanalytics&task=realstats.showEntity&format=json' . "';  
					var jrealtimeIntervalRealStats = '" . $componentConfig->get('realtimerefresh') . "';
					jQuery(function(){
						new JRealtimeControllerRealtimestats(); 
					});
				");
		// Inject js translations
		$translations = array(	'COM_JREALTIME_PIEGRAPHTITLE', 
								'COM_JREALTIME_TEXTSTATSTITLE', 
								'COM_JREALTIME_BARGRAPHTITLE', 
								'COM_JREALTIME_USERS',
								'COM_JREALTIME_USERSSTATSTITLE',
								'COM_JREALTIME_TITLENAME',
								'COM_JREALTIME_TITLEUSERNAME',
								'COM_JREALTIME_TITLETYPE',
								'COM_JREALTIME_TITLETIME',
								'COM_JREALTIME_TITLENOWPAGE',
								'COM_JREALTIME_PERPAGESTATSTITLE',
								'COM_JREALTIME_TITLENUMUSERS',
								'COM_JREALTIME_TITLELASTVISIT',
								'COM_JREALTIME_DBERROR',
								'COM_JREALTIME_NA');
		$this->injectJsTranslations($translations, $doc);
		
		// Custom CSS lib files
		$wa = $doc->getWebAssetManager();
		
		// Kendo lib
		$wa->registerAndUseScript ( 'jrealtime.kendo.core', 'administrator/components/com_jrealtimeanalytics/js/libraries/kendo/kendo.core.js', [], [], ['jquery']);
		$wa->registerAndUseScript ( 'jrealtime.kendo.data', 'administrator/components/com_jrealtimeanalytics/js/libraries/kendo/kendo.data.js', [], [], ['jquery', 'jrealtime.kendo.core']);
		$wa->registerAndUseScript ( 'jrealtime.kendo.chart', 'administrator/components/com_jrealtimeanalytics/js/libraries/kendo/kendo.chart.js', [], [], ['jquery', 'jrealtime.kendo.core', 'jrealtime.kendo.data']);
		$wa->registerAndUseScript ( 'jrealtime.kendo.stringify', 'administrator/components/com_jrealtimeanalytics/js/libraries/kendo/jquery.stringify.js', [], [], ['jquery', 'jrealtime.kendo.core', 'jrealtime.kendo.data', 'jrealtime.kendo.chart']);
		
		// Core MVC JS
		$wa->registerAndUseScript ( 'jrealtime.realtimestats.view', 'administrator/components/com_jrealtimeanalytics/js/views/realtimestats.view.js', [], [], ['jquery']);
		$wa->registerAndUseScript ( 'jrealtime.realtimestats.model', 'administrator/components/com_jrealtimeanalytics/js/models/realtimestats.model.js', [], [], ['jquery']);
		$wa->registerAndUseScript ( 'jrealtime.realtimestats.controller', 'administrator/components/com_jrealtimeanalytics/js/controllers/realtimestats.controller.js', [], [], ['jquery']);
		
		// Aggiunta toolbar
		$this->addDisplayToolbar();
		
		// Display template
		parent::display();
	}
}