{# errors/layout.html.twig #}
{# Base error layout #}
{% extends 'itop-portal-base/portal/templates/layout.html.twig' %}

{% block pStyleinline %}
	<style>
		.well {
			margin: 50px auto;
			text-align: center;
			padding: 25px;
			min-width: 600px;
			max-width: 1000px;
		}
		h1, h2, h3, p {
			margin: 0;
		}
		p {
			font-size: 17px;
			margin-top: 25px;
		}
		p a.btn {
			margin: 0 5px;
		}

		{# Stack trace is only displayed in debug #}
		{% if app['kernel'].debug == true %}
			code {
				background-color: transparent;
			}

			{# Include SF style for the stack trace #}
			{{ include('@Twig/exception.css.twig') }}

			{# In production (SF context, not iTop), we hide some element as the code will not be displayed #}
			{% if app['kernel'].environment == 'prod' %}
				.trace-line-header > .icon{
					display: none !important;
				}
				.trace-code{
					display: none !important;

				}
			{% endif %}
		{% endif %}
	</style>
{% endblock %}

{% block pNavigationWrapper %}
{% endblock %}

{% block pMainWrapper %}
	<div class="container">
		<div class="well">
			<h1><div class="ion ion-alert-circled"></div> {{ error_title }}</h1>
			<p>{{ error_message }}</p>
			<p>{{ 'Error:HTTP:GetHelp'|dict_format(constant('ITOP_APPLICATION_SHORT')) }}</p>
			<p>
				<a class="btn btn-default" href="#" onclick="history.back(); return false;"><span class="fas fa-arrow-left"></span> {{ 'Page:GoPreviousPage'|dict_s }}</a>
				<a class="btn btn-default" href=""><span class="fas fa-redo"></span> {{ 'Page:ReloadPage'|dict_s }}</a>
				<a class="btn btn-default" href="{{ app['url_generator'].generate('p_home') }}"><span class="fas fa-home"></span> {{ 'Page:GoPortalHome'|dict_s }}</a>
			</p>
		</div>

		{% if app['kernel'].debug == true %}
			<div class="exceptions-container">
				{# Note: The following is copied by the '@Twig/Exception/exception.html.twig' #}
				{% set exception_as_array = exception.toarray %}
				{% set _exceptions_with_user_code = [] %}
				{% for i, e in exception_as_array %}
					{% for trace in e.trace %}
						{% if (trace.file is not empty) and ('/vendor/' not in trace.file) and ('/var/cache/' not in trace.file) and not loop.last %}
							{% set _exceptions_with_user_code = _exceptions_with_user_code|merge([i]) %}
						{% endif %}
					{% endfor %}
				{% endfor %}
				<h3 class="tab-title">
					{% if exception_as_array|length > 1 %}
						Exceptions <span class="badge">{{ exception_as_array|length }}</span>
					{% else %}
						Exception
					{% endif %}
				</h3>

				<div class="tab-content">
					{% for i, e in exception_as_array %}
						{{ include('@Twig/Exception/traces.html.twig', { exception: e, index: loop.index, expand: i in _exceptions_with_user_code or (_exceptions_with_user_code is empty and loop.first) }, with_context = false) }}
					{% endfor %}
				</div>
			</div>
		{% endif %}
	</div>
{% endblock %}

{% block pPageLiveScripts %}
	{{ include('@Twig/base_js.html.twig') }}
{% endblock %}