{% extends "base.html" %}

{% block title %}
	{{ _("Create a release") }} - {{ package.title }}
{% endblock %}

{% block content %}
	<h1>{{ _("Create a release") }}</h1>

	{% if package.update_config %}
		<p class="alert alert-secondary mb-4">
			<a class="float-end btn btn-sm btn-secondary" href="{{ package.get_url('packages.update_config') }}">{{ _("Settings") }}</a>
			{% if package.update_config.make_release %}
				{{ _("You have automatic releases enabled.") }}
			{% else %}
				{{ _("You have Git update notifications enabled.") }}
				{{ _("You can enable automatic updates in the update settings.") }}
			{% endif %}
		</p>
	{% else %}
		<p class="alert alert-info mb-4">
			{% if package.repo %}
				<a class="float-end btn btn-sm btn-info" href="{{ package.get_url('packages.setup_releases') }}">{{ _("Set up") }}</a>
				<i class="fas fa-info me-2"></i>

				{{ _("You can create releases automatically when you push commits or tags to your repository.") }}
			{% else %}
				<a class="float-end btn btn-sm btn-info" href="{{ package.get_url('packages.create_edit') }}">{{ _("Add Git repo") }}</a>
				<i class="fas fa-info me-2"></i>

				{{ _("Using Git would allow you to create releases automatically when you push code or tags.") }}
			{% endif %}
		</p>
	{% endif %}

	{% from "macros/forms.html" import render_field, render_submit_field, render_radio_field %}
	<form method="POST" action="" enctype="multipart/form-data">
		{{ form.hidden_tag() }}

		<h3>{{ _("1. Name release") }}</h3>

		{{ render_field(form.name, hint=_("Release short name. Eg: 1.0.0 or 2018-05-28")) }}
		{{ render_field(form.title, placeholder=_("Same as name"), hint=_("Human-readable name. Eg: 1.0.0 - The Trains Update")) }}
		{{ render_field(form.release_notes, fieldclass="form-control markdown") }}

		<h3 class="mt-5">{{ _("2. Set the content") }}</h3>

		{{ render_radio_field(form.upload_mode) }}

		{% if package.repo %}
			{{ render_field(form.vcs_label, placeholder=_("Leave blank to use default branch"), class_="mt-3",
					pattern="[A-Za-z0-9/._-]+") }}
		{% endif %}

		{{ render_field(form.file_upload, fieldclass="form-control-file", class_="mt-3", accept=".zip") }}

		<p>
			{{ _("Take a look at the <a href='/help/package_config/'>Package Configuration and Releases Guide</a> for
			tips on customising releases.") }}
		</p>

		<h3 class="mt-5">{{ _("3. Supported Minetest versions") }}</h3>

		<div class="row">
			{{ render_field(form.min_rel, class_="col-sm-6") }}
			{{ render_field(form.max_rel, class_="col-sm-6") }}
		</div>

		<p id="minmax_warning" class="text-danger d-none">
			{{ _("Maximum must be greater than or equal to the minimum!") }}
		</p>

		<p id="latest_release" class="text-warning d-none">
			{% set last = form.max_rel | last_it %}
			<strong>
				{{ _("Are you sure your package doesn't work on versions after %(version)s?", version=last.label) }}
			</strong>
			{{ _("Only set the maximum version if you know that it doesn't work on newer Minetest versions.") }}
			{{ _("Don't set the maximum version just because you haven't tested it on newer versions.") }}
		<p>

		<p>
			<i class="fas fa-exclamation-circle me-2"></i>
			{{ _("The .conf of your package can <a href='/help/package_config/'>set this automatically</a>,
			which will override your selection.") }}
		</p>

		<p>
			{{ _("Set the minimum and maximum Minetest versions supported.
			This release will be hidden to clients outside of that range. ") }}
			<br>
			{{ _("Leave both as None if in doubt.") }}
		</p>

		<p class="mt-5">
			{{ render_submit_field(form.submit) }}
		</p>
	</form>
{% endblock %}

{% from "macros/forms.html" import easymde_scripts %}
{% block scriptextra %}
	{{ easymde_scripts() }}
	<script src="/static/js/release_minmax.js?v=2"></script>
	<script src="/static/js/release_new.js?v=2"></script>
{% endblock %}