{% extends 'base.html' %}

{% block body %}
<form action="{{ url_for("invite.new_submit") }}" method="POST" class="form">
	<div class="form-group">
		<label for="single-use">{{_('Link Type')}}</label>
		<select class="form-control" id="single-use" name="single-use">
			<option value="1">{{_('Valid for a single successful use')}}</option>
			<option value="0">{{_('Multi-use')}}</option>
		</select>
	</div>
	<div class="form-group">
		<label for="valid-until">{{_('Valid Until')}}</label>
		<input class="form-control" type="datetime-local" id="valid-until" name="valid-until" value="{{ (datetime.now() + timedelta(hours=36)).replace(hour=23, minute=59, second=59, microsecond=0).isoformat(timespec='minutes') }}">
		<small class="text-muted">{{_('Must be within the next %(max_valid_days)d days', max_valid_days=config['INVITE_MAX_VALID_DAYS'])}}</small>
	</div>
	{% if allow_signup %}
	<div class="form-group">
		<label for="allow-signup">{{_('Account Registration')}}</label>
		<select class="form-control" id="allow-signup" name="allow-signup">
			<option value="1">{{_('Link allows account registration')}}</option>
			<option value="0">{{_('No account registration allowed')}}</option>
		</select>
	</div>
	{% else %}
	<input type="hidden" name="allow-signup" value="0">
	{% endif %}
	{% if roles %}
	<div class="form-group">
		<label for="valid-until">{{_('Granted Roles')}}</label>
		<table class="table table-sm">
			<thead>
				<tr>
					<th scope="col"></th>
					<th scope="col">{{_('Name')}}</th>
					<th scope="col">{{_('Description')}}</th>
				</tr>
			</thead>
			<tbody>
				{% for role in roles|sort(attribute="name") if not role.is_default %}
				<tr>
					<td>
						<div class="form-check">
							<input class="form-check-input" type="checkbox" id="role-{{ role.id }}" name="role-{{ role.id }}" value="1" {{ 'checked' if 'role-%d'%role.id in request.values }}>
						</div>
					</td>
					<td>{{ role.name }}</td>
					<td>{{ role.description }}</td>
				</tr>
				{% endfor %}
			</tbody>
		</table>
	</div>
	{% endif %}
	<button type="submit" class="btn btn-primary"><i class="fa fa-save" aria-hidden="true"></i> {{_('Create Link')}}</button>
	<a href="{{ url_for("invite.index") }}" class="btn btn-secondary">{{_('Cancel')}}</a>
</form>
{% endblock %}
