<?php
/**
 *
 * @copyright Copyright (c) Miroslav Marek <mirek.marek@web-jet.cz>
 * @license http://www.php-jet.net/license/license.txt
 * @author Miroslav Marek <mirek.marek@web-jet.cz>
 */

use Jet\Debug_Profiler_Run;
use Jet\SysConf_Jet_MVC;
use Jet\SysConf_Jet_Autoloader;
use Jet\SysConf_Jet_PackageCreator_CSS;
use Jet\SysConf_Jet_PackageCreator_JavaScript;


/**
 * @var Debug_Profiler_Run $run
 * @var string $URL
 */

$root_block = $run->getBlocks()[0];
$duration = round($root_block->getDuration()*1000, 2);
$memory = $root_block->getMemoryUsageDiff()/1024;

$show_cache_state = function( string $title, bool $state ) {
	?>
	<div class="__state_title"><?=$title?></div>
	<?php if($state): ?>
		<div class="__state_yes">YES</div>
	<?php else: ?>
		<div class="__state_no">NO</div>
	<?php endif;
};


require 'status-bar/css.phtml';
require 'status-bar/js.phtml';
?>
<div id="__profiler__spacer__">

</div>
<div id="__profiler__" class="__result">
	<div class="__close_btn" onclick="__profiler__close();">&#x2715;</div>
	<div class="__title"><a href="<?=$URL?>" target="_blank"><b>PROFILER</b><br>Show details</a></div>
	<div>
		Duration:<br>
		<b><?=$duration?> ms</b>
	</div>
	<div>
		Memory usage:<br>
		<b><?=round($memory, 3)?> KiB</b>
	</div>
	<div>
		SQL:<br>
		<b><?=count($run->getSqlQueries())?> queries</b>
	</div>
	<div>
		Cache state:<br>
		<div class="__state">
			<?php $show_cache_state('Autoloader', SysConf_Jet_Autoloader::getCacheEnabled() ); ?>
			<?php $show_cache_state('MVC', SysConf_Jet_MVC::getCacheEnabled() ); ?>
		</div>
	</div>
	<div>
		Packager state:<br>
		<div class="__state">
			<?php $show_cache_state('JS', SysConf_Jet_PackageCreator_JavaScript::getEnabled() ); ?>
			<?php $show_cache_state('CSS', SysConf_Jet_PackageCreator_CSS::getEnabled() ); ?>
		</div>
	</div>
</div>
