{% extends 'layout.html.twig' %}

{% block content %}
	<section class="row-fluid">
		<div class="span2 sidebar">
			{% set namespace = project.namespace %}
			{{ block('sidebarNamespaces') }}
		</div>
	</section>
	<section class="row-fluid">
		<div class="span10 offset2">
			<div class="row-fluid">
				<div class="span8 content class">
					<nav>
						{#<a href="" class="pull-left">&laquo; NamespaceAssembler</a>#}
						{{ node.namespace|route|raw }}
						<i class="fa-solid fa-turn-up"></i>
						{#<a href="" class="pull-right">ClassAssembler &raquo;</a>#}
					</nav>
					{% if project.settings.shouldIncludeSource %}
						<a href="#source-view" role="button" class="pull-right btn" data-toggle="modal">
							<i class="fa-solid fa-code"></i>
						</a>
					{% endif %}

					<h1>
						<small>{{ node.namespace }}</small>
						{{ node.name }}</h1>
					<p>
						<em>{{ node.summary }}</em>
					</p>
					{{ node.description|markdown|raw }}
					{% for tag_name, tags in node.tags %}
						{% if tag_name in ['example'] %}
							{% if loop.first %}
								<h3>Examples</h3>
							{% endif %}
							{% for tag in tags %}
								<h4>{{ tag.description|escape }}</h4>
								<pre class="pre-scrollable">{{ tag.example|escape }}</pre>
							{% endfor %}
						{% endif %}
					{% endfor %}
					<section id="summary">
						<h2>Summary</h2>
						<section class="row-fluid heading">
							<section class="span4">
								<a href="#methods">Methods</a>
							</section>
							<section class="span4">
								<a href="#properties">Properties</a>
							</section>
							<section class="span4">
								<a href="#constants">Constants</a>
							</section>
						</section>
						<section class="row-fluid public">
							<section class="span4">
								{% set public_methods = [] %}
								{% for method in node.inheritedMethods.merge(node.methods.merge(node.magicMethods)) %}
									{% if method.visibility == 'public' %}
										{% set public_methods = public_methods|merge([method]) %}
									{% endif %}
								{% endfor %}

								{% if public_methods|length > 0 %}
									{% for method in public_methods %}
										<a href="{{ method|route('url') }}" class="{{ method.deprecated ? 'deprecated' }}">{{ method.name }}</a><br/>
									{% endfor %}
								{% else %}
									<em>No public methods found</em>
								{% endif %}
							</section>
							<section class="span4">
								{% set public_properties = [] %}
								{% for property in node.inheritedProperties.merge(node.properties.merge(node.magicProperties)) %}
									{% if property.visibility == 'public' %}
										{% set public_properties = public_properties|merge([property]) %}
									{% endif %}
								{% endfor %}

								{% if public_properties|length > 0 %}
									{% for property in public_properties %}
										<a href="{{ property|route('url') }}" class="{{ property.deprecated ? 'deprecated' }}">{{ property.name }}</a><br/>
									{% endfor %}
								{% else %}
									<em>No public properties found</em>
								{% endif %}
							</section>
							<section class="span4">
								{% set public_constants = [] %}
								{% for constant in node.inheritedConstants.merge(node.constants) %}
									{% if constant.visibility == 'public' %}
										{% set public_constants = public_constants|merge([constant]) %}
									{% endif %}
								{% endfor %}

								{% if public_constants|length > 0 %}
									{% for constant in public_constants %}
										<a href="{{ constant|route('url') }}" class="{{ constant.deprecated ? 'deprecated' }}">{{ constant.name }}</a><br/>
									{% endfor %}
								{% else %}
									<em>No public constants found</em>
								{% endif %}
							</section>
						</section>
						<section class="row-fluid protected">
							<section class="span4">
								{% set protected_methods = [] %}
								{% for method in node.inheritedMethods.merge(node.methods.merge(node.magicMethods)) %}
									{% if method.visibility == 'protected' %}
										{% set protected_methods = protected_methods|merge([method]) %}
									{% endif %}
								{% endfor %}

								{% if protected_methods|length > 0 %}
									{% for method in protected_methods %}
										<a href="{{ method|route('url') }}" class="{{ method.deprecated ? 'deprecated' }}">{{ method.name }}</a><br/>
									{% endfor %}
								{% else %}
									<em>No protected methods found</em>
								{% endif %}
							</section>
							<section class="span4">
								{% set protected_properties = [] %}
								{% for property in node.inheritedProperties.merge(node.properties.merge(node.magicProperties)) %}
									{% if property.visibility == 'protected' %}
										{% set protected_properties = protected_properties|merge([property]) %}
									{% endif %}
								{% endfor %}

								{% if protected_properties|length > 0 %}
									{% for property in protected_properties %}
										<a href="{{ property|route('url') }}" class="{{ property.deprecated ? 'deprecated' }}">{{ property.name }}</a><br/>
									{% endfor %}
								{% else %}
									<em>No protected properties found</em>
								{% endif %}
							</section>
							<section class="span4">
								{% set protected_constants = [] %}
								{% for constant in node.inheritedConstants.merge(node.constants) %}
									{% if constant.visibility == 'protected' %}
										{% set protected_constants = protected_constants|merge([constant]) %}
									{% endif %}
								{% endfor %}

								{% if protected_constants|length > 0 %}
									{% for constant in protected_constants %}
										<a href="{{ constant|route('url') }}" class="{{ constant.deprecated ? 'deprecated' }}">{{ constant.name }}</a><br/>
									{% endfor %}
								{% else %}
									<em>No protected constants found</em>
								{% endif %}
							</section>
						</section>
						<section class="row-fluid private">
							<section class="span4">
								{% set private_methods = [] %}
								{% for method in node.inheritedMethods.merge(node.methods.merge(node.magicMethods)) %}
									{% if method.visibility == 'private' %}
										{% set private_methods = private_methods|merge([method]) %}
									{% endif %}
								{% endfor %}

								{% if private_methods|length > 0 %}
									{% for method in private_methods %}
										<a href="{{ method|route('url') }}" class="{{ method.deprecated ? 'deprecated' }}">{{ method.name }}</a><br/>
									{% endfor %}
								{% else %}
									<em>No private methods found</em>
								{% endif %}
							</section>
							<section class="span4">
								{% set private_properties = [] %}
								{% for property in node.inheritedProperties.merge(node.properties.merge(node.magicProperties)) %}
									{% if property.visibility == 'private' %}
										{% set private_properties = private_properties|merge([property]) %}
									{% endif %}
								{% endfor %}

								{% if private_properties|length > 0 %}
									{% for property in private_properties %}
										<a href="{{ property|route('url') }}" class="{{ property.deprecated ? 'deprecated' }}">{{ property.name }}</a><br/>
									{% endfor %}
								{% else %}
									<em>No private properties found</em>
								{% endif %}
							</section>
							<section class="span4">
								{% set private_constants = [] %}
								{% for constant in node.inheritedConstants.merge(node.constants) %}
									{% if constant.visibility == 'private' %}
										{% set private_constants = private_constants|merge([constant]) %}
									{% endif %}
								{% endfor %}

								{% if private_constants|length > 0 %}
									{% for constant in private_constants %}
										<a href="{{ constant|route('url') }}" class="{{ constant.deprecated ? 'deprecated' }}">{{ constant.name }}</a><br/>
									{% endfor %}
								{% else %}
									<em>No private constants found</em>
								{% endif %}
							</section>
						</section>
					</section>
				</div>
				<aside class="span4 detailsbar">
					{% if node.abstract %}
						<span class="label label-info">abstract</span>
					{% endif %}
					{% if node.final %}
						<span class="label label-info">final</span>
					{% endif %}

					{% if method.deprecated %}
						<aside class="alert alert-block alert-info">
							<h4>Deprecated</h4>
							{{ method.tags.deprecated[0].description }}
						</aside>
					{% endif %}

					<dl>
						<dt>File</dt>
						<dd>
							<a href="{{ node.file|route('url') }}">
								<div class="path-wrapper">{{ node.path }}</div>
							</a>
						</dd>
						{% if node.package.name is not empty and node.package.name != '\\' %}
							<dt>Package</dt>
							<dd>
								<div class="namespace-wrapper">{{ node.package.parent.name != '\\' ? (node.package.parent.name ~ '\\' ~ node.package.name) : node.package.name }}</div>
							</dd>
						{% endif %}
						<dt>Class hierarchy</dt>
						<dd class="hierarchy">
							{% set class = node.parent %}
							{% block hierarchy_element %}
								{% if class %}
									{% set child = class %}
									{% set class = class.parent %}
									{{ block('hierarchy_element') }}
									<div class="namespace-wrapper">{{ child|route|raw }}</div>
								{% endif %}
							{% endblock %}
							<div class="namespace-wrapper">{{ node.fullyQualifiedStructuralElementName }}</div>
						</dd>

						{% for interface in node.interfaces %}
							{% if loop.first %}
								<dt>Implements</dt>
							{% endif %}
							<dd>
								<a href="{{ interface|route('url') }}">
									<div class="namespace-wrapper">{{ interface.fullyQualifiedStructuralElementName }}</div>
								</a>
							</dd>
						{% endfor %}

						{% for trait in node.usedTraits %}
							{% if loop.first %}
								<dt>Uses traits</dt>
							{% endif %}
							<dd>
								{% if trait.fullyQualifiedStructuralElementName %}
									<a href="{{ trait|route('url') }}">
									{% endif %}
									<div class="namespace-wrapper">{{ trait.fullyQualifiedStructuralElementName ?: trait }}</div>
									{% if trait.fullyQualifiedStructuralElementName %}
									</a>
								{% endif %}
							</dd>
						{% endfor %}

						{# TODO: expensive action; replace with an index or precompiled list in descriptors #}
						{#
						                        {% for child in project.indexes.elements if child.parent.fullyQualifiedStructuralElementName == node.fullyQualifiedStructuralElementName %}
						                            {% if loop.first %}
						                        <dt>Children</dt>
						                            {% endif %}
						                            <dd><a href="{{ child|route('url') }}"><div class="namespace-wrapper">{{ child.fullyQualifiedStructuralElementName }}</div></a></dd>
						                        {% endfor %}
						#}

						{% for tag_name, tags in node.tags %}
							{% if tag_name in ['link', 'see'] %}
								{% if loop.first %}
									<dt>See also</dt>
								{% endif %}
								{% for tag in tags %}
									<dd>
										<a href="{{ (tag.reference|route('url')) ?: tag.link }}">
											<span class="namespace-wrapper">{{ tag.description ?: tag.reference }}</span>
										</a>
									</dd>
								{% endfor %}
							{% endif %}
						{% endfor %}
						{% for tag_name, tags in node.tags %}
							{% if tag_name in ['uses'] %}
								{% if loop.first %}
									<dt>Uses</dt>
								{% endif %}
								{% for tag in tags %}
									<dd>
										<span class="namespace-wrapper">
											<a href="{{ tag.reference|route('url') }}">{{ tag.reference }}</a> 
											{{ tag.description }}
										</span>
									</dd>
								{% endfor %}
							{% endif %}
						{% endfor %}

						{#<dt>Categories</dt>#}
						{#<dd><a href="">Assemblers</a></dd>#}
					</dl>
					<h2>Tags</h2>
					<table class="table table-condensed">
						{% set filtered_tags = node.tags|filter(tag => tag.key not in ['link', 'see', 'uses', 'abstract', 'example', 'method', 'property', 'property-read', 'property-write', 'package', 'subpackage']) %}
						{% if filtered_tags is not empty %}
							{% for tag_name, tags in filtered_tags %}
								<tr>
									<th>
										{{ tag_name }}
									</th>
									<td>
										{% for tag in tags %}
											{% if tag.version %}
												{{ tag.version }}
											{% endif %}
											{{ tag.description|markdown|raw }}
										{% endfor %}
									</td>
								</tr>
							{% endfor %}
						{% else %}
							<tr>
								<td colspan="2">
									<em>None found</em>
								</td>
							</tr>
						{% endif %}
					</table>
				</aside>
			</div>

			{% set constants = node.inheritedConstants.merge(node.constants) %}
			{% if constants|length > 0 %}
				<a id="constants" name="constants"></a>
				<div class="row-fluid">
					<div class="span8 content class">
						<h2>Constant</h2>
					</div>
					<aside class="span4 detailsbar"></aside>
				</div>

				{% for constant in constants %}
					{% if constant.visibility == 'public' %}
						{{ block('constant') }}
					{% endif %}
				{% endfor %}

				{% for constant in constants %}
					{% if constant.visibility == 'protected' %}
						{{ block('constant') }}
					{% endif %}
				{% endfor %}

				{% for constant in constants %}
					{% if constant.visibility == 'private' %}
						{{ block('constant') }}
					{% endif %}
				{% endfor %}
			{% endif %}

			{% set properties = node.inheritedProperties.merge(node.properties.merge(node.magicProperties)) %}
			{% if properties|length > 0 %}
				<a id="properties" name="properties"></a>
				<div class="row-fluid">
					<div class="span8 content class">
						<h2>Properties</h2>
					</div>
					<aside class="span4 detailsbar"></aside>
				</div>

				{% for property in properties %}
					{% if property.visibility == 'public' %}
						{{ block('property') }}
					{% endif %}
				{% endfor %}
				{% for property in properties %}
					{% if property.visibility == 'protected' %}
						{{ block('property') }}
					{% endif %}
				{% endfor %}
				{% for property in properties %}
					{% if property.visibility == 'private' %}
						{{ block('property') }}
					{% endif %}
				{% endfor %}
			{% endif %}

			{% set methods = node.inheritedMethods.merge(node.methods.merge(node.magicMethods)) %}
			{% if methods|length > 0 %}
				<a id="methods" name="methods"></a>
				<div class="row-fluid">
					<div class="span8 content class">
						<h2>Methods</h2>
					</div>
					<aside class="span4 detailsbar"></aside>
				</div>

				{% for method in methods %}
					{% if method.visibility == 'public' %}
						{{ block('method') }}
					{% endif %}
				{% endfor %}
				{% for method in methods %}
					{% if method.visibility == 'protected' %}
						{{ block('method') }}
					{% endif %}
				{% endfor %}
				{% for method in methods %}
					{% if method.visibility == 'private' %}
						{{ block('method') }}
					{% endif %}
				{% endfor %}
			{% endif %}
		</div>
	</section>

	<div id="source-view" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="source-view-label" aria-hidden="true">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
			<h3 id="source-view-label">{{ node.file.name }}</h3>
		</div>
		<div class="modal-body">
			<pre data-src="{{ path('files/' ~ node.path ~ '.txt')|raw }}" class="language-php line-numbers"></pre>
		</div>
	</div>
{% endblock %}
