{% extends 'layout.twig' %}

{% macro renderItem(entity) %}

	{% set path = 
		entity.SOURCE == 'OXACHARTS_REQ' 
		? path('EtatStatistique.Visu.detail', {id: entity.CODETAT }) 
		: (
			entity.NOMFIC != '' and entity.TYPERES == ''
			? path('EtatStatistiques.GestionStatistique.chargeFichierEtat', {'codEtat' : entity.CODETAT})
			: path('EtatStatistiques.GestionStatistique.detailEtatWsdl', {codEtat: entity.CODETAT })
		)
	%}
	<a class ="tuilesEtat nobr white-tooltip" href ="{{ path }}" style="margin-left:10px;">
		<span class="d-block relative">
			<img class ="pictos" src="{{
				entity.TYPERES == 'T' 
				? baseUrl('/IconeV2/Global/Table-mode.svg') 
				: baseUrl('/IconeV2/Global/graphic-mode.svg') }}"
			>
			<span class="tuilesTitle">{{ entity.DESCRIPT | trad }}</span>
			{% if entity.COMMENTAI %}
			<span class="infos_tooltip">{{ entity.COMMENTAI }}</span>
			{% endif %}
		</span>
	</a>
{% endmacro %}

{% block body %}
<div class="contenu clearfix"  id="accueil">

<div class="fond_blanc padding15" style ="margin-left: 24px;">


<div class="clearfix row">
	<h1>{{'Etats Statistiques' |trad}}</h1>
	{{ ariane() }}

	{{ specifique('HtmlExtension', 'specifiqueStatistique', {}) }}
	{% if listeSansTheme %}
	<h2 onclick = "showContent('content_id_{{i}}');" class="nobr">
		{{'Etats sans thème' | trad}}
		<img style="margin-left:10px" class ="pictos" id="img_content_id_{{i}}" src='{{ baseUrl('IconeV2/Misc/chevron-down.svg') }}' width="20px">
	</h2>
	{% endif %}

	<div id="content_id_" class="relative">
		{% for sansTheme in listeSansTheme %}
			{{ _self.renderItem(sansTheme) }}
		{% endfor %}
	</div>

	{% set lastTheme = '' %} 
    {% set i = 0 %} 

	{% for entity in listeTheme %}
	
		{# TODO : index theme by CODTHEM from the controller #}
		{% if lastTheme != entity.CODTHEM %}
			{% if i > 0 %}</div></div>{% endif %}
			<div class="conteneur">
				
			<h2 onclick = "showContent('content_id_{{i}}');" class="nobr">{{entity.LIBELLE | trad }}<img style="margin-left:10px"class ="pictos" id="img_content_id_{{i}}" data-ouvert='1' src='{{ baseUrl('IconeV2/Misc/chevron-down.svg') }}' width="20px"></h2>

			<div id="content_id_{{i}}" class="relative">
			
			{% set i = i + 1 %}
		{% endif %}
		{{ _self.renderItem(entity) }}
		{% set lastTheme = entity.CODTHEM %}
	{% endfor %}
</div></div>
</div></div>

<script>

		function showContent(id)
		{

			if($("#img_"+id).attr('data-ouvert')=='1')
			{
				$("#img_"+id).attr('src', '{{ baseUrl('IconeV2/Misc/chevron-up.svg') }}');
				$("#img_"+id).attr('data-ouvert', '0');
			}
			else
			{
				$("#img_"+id).attr('src', '{{ baseUrl('IconeV2/Misc/chevron-down.svg') }}');
				$("#img_"+id).attr('data-ouvert', '1');
			}
			
			$("#"+id).slideToggle(300);

		}


</script>

{% endblock %}