{% extends 'layouts/layout.twig' %}
{% block title %}{{ __('Setup') }}{% endblock %}
{% set startpage = old.settings.startpage ? old.settings.startpage : settings.startpage %}

{% block content %}
	
	<div class="formWrapper">

		<form method="POST" action="{{ path_for('plugins.save') }}" enctype="multipart/form-data" novalidate>

			<section id="plugins" class="plugins">
			
				<header class="headline">
					<h1>{{ __('Plugins') }}</h1>
					<a class="button" target="_blank" href="https://plugins.typemill.net">{{ __('Plugin Store') }}</a>
				</header>
				
				{% for pluginName,plugin in plugins %}
				
					<fieldset class="large card{{ errors[pluginName] ? ' errors' : '' }}">
						<div class="cardInner cardHead">
							<header>
								<legend>{{ pluginName }}</legend>							
								<div class="cardActive">
									<label class="control-group">{{ __('Active') }}
										<input type="checkbox" class="fc-active" name="{{pluginName}}[active]"{% if settings.plugins[pluginName].active %} checked {% endif %}>
										<span class="checkmark"></span>
									</label>
								</div>
							</header>
							<div id="{{ pluginName }}" class="fc-plugin-version update-banner">{{ plugin.version ? plugin.version : __('Unknown') }}</div>
							
							<div class="cardDescPlugin">
								<p>{{ plugin.description ? __(plugin.description) : __('No description') }}</p>
								
								<ul class="cardInfo">
									<li>{{ plugin.version ? plugin.version : __('Unknown') }}</li><li>
									{{ plugin.licence ? plugin.licence : __('Unkown') }}</li><li>
									{{ __('by') }} {{ plugin.author ? plugin.author : __('Unknown') }}</li>{% if plugin.homepage %}<li>
									<a href="{{ plugin.homepage}}" target="blank">{{ __('Web') }}</a></li>{% endif %}
								</ul>
							</div>
						<div class="cardInner cardFields{{ errors[pluginName] ? ' open' : '' }}">

							{% if plugin.dependencies %}
								<div class="w-100 mt3 pa3 pb4 bg-tm-green white">
									<p>Please make sure that you have installed and activated the following plugins:</p>
									{% for dependency in plugin.dependencies %}
										<span class="pa2 mr2 br1 bg-tm-gray black">{{ dependency }}</span> 
									{% endfor %}
								</div>
							{% endif %}
						
							{% for field in plugin.forms.fields %}
								
								{% if field.type == 'fieldset' %}
											
									<fieldset class="subfield">
										<legend>{{ field.legend }}</legend>
											{% for field in field.fields %}
												{% include '/partials/fields.twig' with {'itemName' : pluginName, 'object' : 'plugins' } %}
											{% endfor %}
										</fieldset>
											
								{% else %}
								
									{% include '/partials/fields.twig' with {'itemName' : pluginName, 'object' : 'plugins' } %}
								
								{% endif %}
								
							{% endfor %}
							
						</div>
							<button type="button" class="plugin-button fc-settings{{ settings.plugins[pluginName].active ? ' active' : '' }}{{ plugin.forms.fields|length > 0 ? ' has-settings' : ' no-settings'}}">{{ plugin.forms.fields|length > 0 ? __('Settings') ~ ' <span class="button-arrow"></span>' : '&nbsp;'}}</button>
						</div>
						
					</fieldset>
					
				{% endfor %}
			
			</section>
			
			<input type="submit" value="{{ __('Save All Settings') }}" />

			{{ csrf_field() | raw }}
			
		</form>

		<script>window.addEventListener('load', function () { autosize(document.querySelectorAll('textarea'));})</script>
	
	</div>
	
{% endblock %}