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

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

			<section id="themes" class="themes">
			
				<header class="headline">
					<h1>{{ __('Themes') }}</h1>
					<a class="button" target="_blank" href="https://themes.typemill.net">{{ __('Theme Store') }}</a>
				</header>
				
				{% for themeName, theme in themes %}
				
					<form method="POST" id="theme-{{ themeName }}" action="{{ path_for('themes.save') }}" enctype="multipart/form-data">
					
						<fieldset class="card{{ errors[themeName] ? ' errors' : '' }}">
						
							<div class="cardInner cardHead">
								
								{% if theme.img %}
									<img src="{{ base_url() }}/themes/{{themeName}}/{{ theme.img }}" />
								{% else %}
									<div class="no-preview">{{ __('No Preview') }}</div>
								{% endif %}
								
								<div class="cardContent">
									<div id="{{ themeName }}" class="fc-theme-version update-banner">{{ theme.version ? theme.version : __('Unknown') }}</div>
									
									<div class="cardDescription">
										<h2>{{ themeName }}</h2>
										<p>{{ __(theme.description) }}</p>
										<ul class="cardInfo">
											<li>{{ theme.version ? theme.version : __('Unknown') }}</li><li>
											{{ theme.licence ? theme.licence : __('Unkown') }}</li><li>
											{{ __('by') }} {{ theme.author ? theme.author : __('Unknown') }}</li>{% if theme.homepage %}<li>
											<a href="{{ theme.homepage}}" target="blank">{{ __('Web') }}</a></li>{% endif %}
										</ul>
									</div>
								</div>
									
								<div class="cardInner cardFields{{ errors[themeName] ? ' open' : '' }}">
								
									{% for field in theme.forms.fields %}
										
										{% if field.type == 'fieldset' %}
											
											<fieldset class="subfield">
												<legend>{{ __( field.legend ) }}</legend>
												{% for field in field.fields %}
													{% include '/partials/fields.twig' with {'itemName' : themeName, 'object' : 'themes' } %}
												{% endfor %}
											</fieldset>
											
										{% else %}
										
											{% include '/partials/fields.twig' with {'itemName' : themeName, 'object' : 'themes' } %}
								
										{% endif %}
								
									{% endfor %}
									
								</div>
								<div class="button-box">
									<input type="hidden" name="theme" value="{{ themeName }}">
										
									<div class="medium">
										<button type="button" id="{{themeName}}-toggle" class="theme-button fc-settings{{ (settings.theme == themeName) ? ' active' : '' }}{{ theme.forms.fields|length > 0 ? ' has-settings' : ' no-settings'}}">{{ theme.forms.fields|length > 0 ? __('Settings') ~ ' <span class="button-arrow"></span>' : __('No Settings')}}</button>
									</div>
									<div class="medium">
										<input type="submit" id="{{themeName}}-submit" value="{{ __('Save Theme') }}" />
									</div>
								</div>								
							</div>
							
						</fieldset>
						
						{{ csrf_field() | raw }}

					</form>
				
				{% endfor %}

			</section>

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