{% extends 'server_control_panel/base.html' %}

{% load i18n static localcosmos_tags %}

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

		<h2>{% if app %}{% blocktrans with name=app.name %}Update {{ name }}{% endblocktrans %}{% else %}{% trans 'Install new app' %}{% endif %}</h2>

		{% if success %}
			<div class="row">
				<div class="col-12">
					<div class="alert alert-success">
						{% trans 'Your app has been installed successfully. You can check its status in the overview.' %}
					</div>
				</div>
				<div class="col-12 mt-3">
					<a href="{% url 'scp:home' %}" class="btn btn-outline-primary">{% trans 'Overview' %}</a>
				</div>
			</div>
		{% else %}

			{% if app %}
			{% else %}
				<div class="row">
					<div class="col-12">
						<div class="card">
							<div class="card-header">
								{% trans 'Important information' %}
							</div>
							<div class="card-body">
								<h5 class="card-title">How to make your apps run</h5>
								<p class="card-text">
									<ul>
										<li>{% blocktrans %}Your web app will be installed in {{ localcosmos_apps_root }}APP_UID/{% endblocktrans %}</li>
										<li>{% trans 'You can look up your APP_UID on localcosmos.org' %}</li>
										<li>{% trans 'Your webserver (nginx or apache) will serve your web app, not django' %}</li>
										<li>{% blocktrans %}Make sure to set an alias to {{ localcosmos_apps_root }}APP_UID/www/ in your web server{% endblocktrans %}</li>
										<li>{% blocktrans %}Your Android and iOS Apps will be able to connect to your server after you installed the web app{% endblocktrans %}</li>
									</ul>
								</p>
								
							</div>
						</div>
					</div>
				</div>
				<hr>
			{% endif %}
			<form action="{% if app %}{% url 'scp:update_app' app.uid %}{% else %}{% url 'scp:install_app' %}{% endif %}" method="POST" enctype="multipart/form-data">{% csrf_token %}
				<div class="row mt-3">
					<div class="col-12">
						{% render_bootstrap_form form %}
					</div>
					{% if errors %}
						<div class="col-12 my-3">
							<div class="alert alert-danger">
								{% trans 'The following errors occured during app import:' %}
								<ul>
									{% for error in errors %}
										<li>{{ error }}</li>
									{% endfor %}
								</ul>
							</div>
						</div>
					{% endif %}
					
					<div class="col-12">
						<button type="submit" class="btn btn-outline-primary">{% trans 'Install' %}</button>
					</div>
				</div>
			</form>
		{% endif %}
	</div>
{% endblock %}
