{% extends "base.html" %}

{% block title %}
	Create a release | {{ package.title }}
{% endblock %}

{% block content %}
	<p class="alert alert-info mb-4">
		<a class="float-right btn btn-sm btn-info" href="{{ url_for('flatpage', path='help/release_webhooks') }}">{{ _("Learn more") }}</a>
		{% if package.author == current_user and package.checkPerm(current_user, "APPROVE_RELEASE") and package.getIsOnGitHub() %}
			<a class="float-right btn btn-sm btn-info mr-2" href="{{ url_for('github.setup_webhook', pid=package.id) }}">{{ _("Setup webhook") }}</a>
			<i class="fas fa-info mr-2"></i>

			{{ _("Set up a webhook on GitHub to create releases automatically.") }}
		{% elif package.repo %}
			<i class="fas fa-info mr-2"></i>

			{{ _("You can create releases automatically when you push commits or tags to your repository.") }}
		{% else %}
			<i class="fas fa-info mr-2"></i>

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

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

		{{ render_field(form.title, placeholder="Human readable. Eg: 1.0.0 or 2018-05-28") }}
		<p class="mb-0">Method</p>
		{{ render_radio_field(form.uploadOpt) }}

		{% if package.repo %}
			{{ render_field(form.vcsLabel, class_="mt-3") }}
		{% endif %}

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

		<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" style="color:#f00; display: none;">
			Maximum must be greater than or equal to the minimum!
		</p>

		<p>
			Note: Min and max versions will be used to hide the package on
			platforms not within the range.
			You cannot select the oldest version for min or the newest version
			for max as this does not make sense - you can't predict the future.<br />
			Leave both as None if in doubt.
		</p>

		{{ render_submit_field(form.submit) }}
	</form>
{% endblock %}

{% block scriptextra %}
	<script src="/static/release_minmax.js?v=1"></script>
	<script>
		function check_opt() {
			if ($("input[name=uploadOpt]:checked").val() == "vcs") {
				$("#fileUpload").parent().hide();
				$("#vcsLabel").parent().show();
			} else {
				$("#fileUpload").parent().show();
				$("#vcsLabel").parent().hide();
			}
		}
		$("input[name=uploadOpt]").change(check_opt);
		check_opt();
	</script>
{% endblock %}
