<fieldset class='filters default collapsible visibleGroup-0'>
	<legend class='collapsible'
		onclick="
			var group = ($(this).up('fieldset').hasClassName('visibleGroup-0')?1:0);
			Element.toggleGroups([
				[$(this).up('fieldset').down('.collapsibleContainer')],
				[$(this).up('fieldset').down('.collapsibleContainer_collapsed')]
			], { visibleGroup:group, updateContainer: $(this).up('fieldset') });
			return false;
		"
		><img class="imgIcon" src="{$smarty.const.SMARTY_BLANKGIF}" /><a href="#;">{$absLang['filters']['label']}</a>
	</legend>

	<ul class="collapsibleContainer">
		{if $reportFilters}
			{foreach $reportFilters->getFilters() as $filterId=>$filter}
				{$class=$filter|get_class}
				{$element=$filterContainer->findElementByName($filterId)}
				{if !$element && $class=="ModulesAbstract\PluginReports\Report\Model\Filters\CorporatesAndSegments"}
					{$fid="$filterId[type]"}
					{$element=$filterContainer->findElementByName($fid)}
				{/if}

				{if !$element && $class=="ModulesAbstract\PluginReports\Report\Model\Filters\CorporatesAndSegmentsAndGroups"}
					{$fid="$filterId[type]"}
					{$element=$filterContainer->findElementByName($fid)}
				{/if}

				{* This code is duplicated because some reports use corporate(s) and segment(s), but gatherers must use filter CorporatesAndSegmentsAndGroups. *}
				{* TODO: remove this after 2022-01-01, if CorporatesAndSegments is no longer used *}
				{if !$element && $class=="ModulesAbstract\PluginReports\Report\Model\Filters\CorporatesAndSegmentsAndGroups"}
					{$fid="corporatesAndSegments[type]"}
					{$element=$filterContainer->findElementByName($fid)}
				{/if}
				{if !$element && $class=="ModulesAbstract\PluginReports\Report\Model\Filters\CorporatesAndSegmentsAndGroups"}
					{$fid="corporateFilter[type]"}
					{$element=$filterContainer->findElementByName($fid)}
				{/if}

				{$filters_undefined_filter_content=''}
				{if !$element}
					{capture assign=filters_undefined_filter_content}{block name=filters_undefined_filter}{/block}{/capture}
					{$filters_undefined_filter_content={$filters_undefined_filter_content|trim}}
					{if $filters_undefined_filter_content}
						{$filters_undefined_filter_content}
					{/if}
				{/if}

				{if !$filters_undefined_filter_content}
					<li class="{if !$element}undefined{/if}">
						{if $element}
							<div class="label">{$element->getLabel()}:</div>
						{else}
							<div class="label">{$filterId}:</div>
						{/if}

						{if $filter|get_class=="ModulesAbstract\PluginReports\Report\Model\Filters\DateInterval"}
							{$value=$filter->getValue()}
							<div class="value DateInterval">{$value['start']|dateTimeFormat} - {$value['end']|dateTimeFormat}</div>
						{elseif $filter|get_class=="ModulesAbstract\PluginReports\Report\Model\Filters\DatetimeInterval"}
							{$value=$filter->getValue()}
							<div class="value DatetimeInterval">{$value['start']['date']|dateTimeFormat} {$value['start']['time']} - {$value['end']['date']|dateTimeFormat} {$value['end']['time']}</div>
						{elseif $filter|get_class=="ModulesAbstract\PluginReports\Report\Model\Filters\Boolean"}
							<div class="value Boolean">
								{$value=$filter->getValue()}
								{if $value}{$_LANG['yes']}{else}{$_LANG['no']}{/if}
							</div>
						{elseif $filter|get_class=="ModulesAbstract\PluginReports\Report\Model\Filters\CorporatesAndSegments"}
							{$value=$filter->getValue()}
							{$possibleValues=['all' => 'all', 'segment' => 'segment', 'corporate' => 'corporate']}

							{if $element}
								{$possibleValues=$element->getPossibleValues()}
							{/if}
							{if $value['type']=='all'}
								<div class="value">{$possibleValues['all']}</div>
							{elseif $value['type']=='segment'}
								<div class="value">{$possibleValues['segment']} {foreach $value['entityIds'] as $id} {corporateSegmentLabel ref=$id} {/foreach}</div>
							{elseif $value['type']=='corporate'}
								<div class="value">{$possibleValues['corporate']} {foreach $value['entityIds'] as $id} {corporateLabel ref=$id} , {/foreach}</div>
							{/if}
						{elseif $filter|get_class=="ModulesAbstract\PluginReports\Report\Model\Filters\CorporatesAndSegmentsAndGroups"}
							{$value=$filter->getValue()}
							{$possibleValues=['all' => 'all', 'segment' => 'segment', 'corporate' => 'corporate', 'groups' => 'groups']}

							{if $element}
								{$possibleValues=$element->getPossibleValues()}
							{/if}
							{if $value['type']=='all'}
								<div class="value">{$possibleValues['all']}</div>
							{elseif $value['type']=='segment'}
								<div class="value">
									{$possibleValues['segment']}
									{foreach $value['entityIds'] as $index => $id}
										{corporateSegmentLabel ref=$id}{if $index < count($value['entityIds'])-1}, {/if}
									{/foreach}
								</div>
							{elseif $value['type']=='corporate'}
								<div class="value">
									{$possibleValues['corporate']}
									{foreach $value['corporateIds'] as $index => $id}
										{corporateLabel ref=$id}{if $index < count($value['corporateIds'])-1}, {/if}
									{/foreach}
								</div>
							{elseif $value['type']=='groups'}
								<div class="value">{$possibleValues['groups']}
									{$groupsList=[]}
									{foreach $value['entityIds'] as $id}
										{$groups = \App\Config\CorporateGroups::getInstance()->getGroupElementDetailsById($id)}
										{$groupsList[$groups['groupName']][] = $id}
									{/foreach}
									{foreach $groupsList as $groupName => $groupElements}
										{$groupId = \App\Config\CorporateGroups::getInstance()->getGroupIdByName($groupName)}
										{$groupElementsList = \App\Config\CorporateGroups::getInstance()->getGroupById($groupId)}
										<span><b>{$groupName}:</b></span>
										{foreach $groupElements as $index => $idElement}
											{$groupElementsList['groupElements'][$idElement]}{if $index < count($groupElements)-1}, {/if}
										{/foreach}
									{/foreach}
								</div>
							{/if}
						{elseif $filter|get_class=="ModulesAbstract\PluginReports\Report\Model\Filters\ListRaw"}
							{$value=$filter->getValue()}
							{$value|join:", "}
						{else}
							<div class="value">{$filter->getValue()}</div>
						{/if}
					</li>
				{/if}
			{/foreach}
		{/if}
	</ul>

	<div class="collapsibleContainer_collapsed" style="display: none;"></div>
</fieldset>


<fieldset class='history default collapsible visibleGroup-1'>
	<legend class='collapsible'
		onclick="
			var group = ($(this).up('fieldset').hasClassName('visibleGroup-0')?1:0);
			Element.toggleGroups([
				[$(this).up('fieldset').down('.collapsibleContainer')],
				[$(this).up('fieldset').down('.collapsibleContainer_collapsed')]
			], { visibleGroup:group, updateContainer: $(this).up('fieldset') });
			return false;
		"
		><img class="imgIcon" src="{$smarty.const.SMARTY_BLANKGIF}" /><a href="#;">{$absLang['reportHistory']['label']}</a>
	</legend>

	<div class="collapsibleContainer" style="display: none;">
		{$mvcView->renderReportHistory($idReport, $reportHistory)}
	</div>

	<div class="collapsibleContainer_collapsed"></div>
</fieldset>


<fieldset class='internalLog default collapsible visibleGroup-1'>
	<legend class='collapsible'
		onclick="
			var group = ($(this).up('fieldset').hasClassName('visibleGroup-0')?1:0);
			Element.toggleGroups([
				[$(this).up('fieldset').down('.collapsibleContainer')],
				[$(this).up('fieldset').down('.collapsibleContainer_collapsed')]
			], { visibleGroup:group, updateContainer: $(this).up('fieldset') });
			return false;
		"
		><img class="imgIcon" src="{$smarty.const.SMARTY_BLANKGIF}" /><a href="#;">{$absLang['reportInternalLog']['label']}</a>
	</legend>

	{if $reportInternalLog}
		{$firstLog=$reportInternalLog|reset}
		<table class="collapsibleContainer" style="display: none;">
			{foreach $reportInternalLog as $log}
				<tr>
					<td class="time">{"%.3fs"|sprintf:($log['time']-$firstLog['time'])}</td>
					<td class="memory">{"%.2fMb"|sprintf:(($log['memory']-$firstLog['memory'])/(1024*1024))}</td>
					<td class="message">{$log['message']}</td>
				</tr>
			{/foreach}
		</table>
	{/if}

	<div class="collapsibleContainer_collapsed"></div>
</fieldset>

<fieldset class='stats default collapsible visibleGroup-1'>
	<legend class='collapsible'
		onclick="
			var group = ($(this).up('fieldset').hasClassName('visibleGroup-0')?1:0);
			Element.toggleGroups([
				[$(this).up('fieldset').down('.collapsibleContainer')],
				[$(this).up('fieldset').down('.collapsibleContainer_collapsed')]
			], { visibleGroup:group, updateContainer: $(this).up('fieldset') });
			return false;
		"
		><img class="imgIcon" src="{$smarty.const.SMARTY_BLANKGIF}" /><a href="#;">{$absLang['stats']['label']}</a>
	</legend>

	<div class="collapsibleContainer" style="display: none;">
		<ul class="general">
			<li><div class="label">total duration</div><div class="value">{"%.2fs"|sprintf:($reportStats['systemResourcesObject']['statsEnd']['time']-$reportStats['systemResourcesObject']['statsStart']['time'])}</div></li>
			<li><div class="label">memory</div><div class="value">{"%.2fMb"|sprintf:(($reportStats['systemResourcesObject']['statsEnd']['mem']-$reportStats['systemResourcesObject']['statsStart']['mem'])/(1024*1024))}</div></li>
			<li>
				<div class="label">server load</div>
				<div class="value">{"%.2f"|sprintf:($reportStats['systemResourcesObject']['statsEnd']['load'])}
				(
					{$sign="+"}
					{if $reportStats['systemResourcesObject']['statsEnd']['load']-$reportStats['systemResourcesObject']['statsStart']['load']<0}
						{$sign="-"}
					{/if}
					{"%s%.2f"|sprintf:$sign:($reportStats['systemResourcesObject']['statsEnd']['load']-$reportStats['systemResourcesObject']['statsStart']['load'])}
				)
				</div>
			</li>
		</ul>

		<ul class="gatherer">
			<li><div class="label">gatherer, raw rows</div><div class="value">{$reportStats['gatherer']['statsEnd']['next:raw']|number_format:0}</div></li>
			<li><div class="label">gatherer, filtered rows</div><div class="value">{$reportStats['gatherer']['statsEnd']['next:filtered']|number_format:0}</div></li>
			<li><div class="label">gatherer, duration</div><div class="value">{$reportStats['gatherer']['statsEnd']['next:time']|number_format:2}s</div></li>
		</ul>

		<ul class="builder">
			<li><div class="label">builder, input rows</div><div class="value">{$reportStats['builder']['statsEnd']['processRow:calls']|number_format:0}</div></li>
			<li><div class="label">builder, duration</div><div class="value">{$reportStats['builder']['statsEnd']['processRow:time']|number_format:2}s</div></li>
		</ul>

		<ul class="exporter">
			<li><div class="label">exporter, input rows</div><div class="value">{$reportStats['exporter']['statsEnd']['exportRow:calls']|number_format:0}</div></li>
			<li><div class="label">exporter, validated values</div><div class="value">{$reportStats['exporter']['statsEnd']['validate:calls']|number_format:0}</div></li>
		</ul>

		<ul class="cache">
			<li><div class="label">cache type</div><div class="value">{$reportStats['systemResourcesObject']['statsEnd']['cache']['type']}</div></li>
			<li><div class="label">cached data, hits</div><div class="value">{$reportStats['systemResourcesObject']['statsEnd']['cache']['hits']|number_format:0}</div></li>
			<li><div class="label">cached data, miss</div><div class="value">{$reportStats['systemResourcesObject']['statsEnd']['cache']['miss']|number_format:0}</div></li>
			<li><div class="label">cached data, hits%</div><div class="value">{$reportStats['systemResourcesObject']['statsEnd']['cache']['hit rate']}</div></li>
			<li><div class="label">cached data, gc</div><div class="value">{$reportStats['systemResourcesObject']['statsEnd']['cache']['gc']|number_format:0}</div></li>
			<li><div class="label">cached data, get</div><div class="value">{$reportStats['systemResourcesObject']['statsEnd']['cache']['get']|number_format:0}</div></li>
			<li><div class="label">cached data, set</div><div class="value">{$reportStats['systemResourcesObject']['statsEnd']['cache']['set']|number_format:0}</div></li>
		</ul>
	</div>

	<div class="collapsibleContainer_collapsed"></div>
</fieldset>
