{% extends "admin_app.html" %}
{% from "library.j2" import action_button, icon, clipboard_button, form_button, custom_form_button, extract_circle_name, invite_type_name, invite_type_description %}
{% block head_lead %}
{{ super() }}
{% include "copy-snippet.html" %}
{% endblock %}
{% block content %}
<h1>{% trans %}Manage invitations{% endtrans %}</h1>
{%- include "admin_create_invite_form.html" -%}
<h2>{% trans %}Pending invitations{% endtrans %}</h2>
{% if invites %}
<form method="POST">
{{- form.csrf_token -}}
<div class="elevated el-2"><table>
	<col/>
	<col class="collapsible"/>
	<col class="collapsible"/>
	<col/>
	<thead>
		<tr>
			<th>{% trans %}Expires{% endtrans %}</th>
			<th class="collapsible">{% trans %}Type{% endtrans %}</th>
			<th class="collapsible">{% trans %}Circle{% endtrans %}</th>
			<th>{% trans %}Actions{% endtrans %}</th>
		</tr>
	</thead>
	<tbody>
{% for invite in invites %}
		<tr>
			<td>{{ (invite.expires - now) | format_timedelta(add_direction=True) }}</td>
			<td class="collapsible"><span class="with-tooltip above" data-tooltip="{% call invite_type_description(invite) %}{% endcall %}">{% call invite_type_name(invite) %}{% endcall %}</span></td>
			<td class="collapsible">
				{#- -#}
				<ul class="inline">
				{%- for group_id in invite.group_ids -%}
					<li>{%- call extract_circle_name(circle_map, group_id) -%}{%- endcall -%}</li>
				{%- endfor -%}
				</ul>
				{#- -#}
			</td>
			<td class="nowrap">
				{%- call action_button("more", url_for(".edit_invite", id_=invite.id_), class="secondary") -%}
					{% trans %}Show invite details{% endtrans %}
				{%- endcall -%}
				{%- call clipboard_button(invite.landing_page, class="primary") -%}
					{% trans %}Copy invite link to clipboard{% endtrans %}
				{%- endcall -%}
				{%- call custom_form_button("remove_link", form.action_revoke.name, invite.id_, class="secondary danger", slim=True) -%}
					{% trans %}Delete invitation{% endtrans %}
				{%- endcall -%}
			</td>
		</tr>
{% endfor %}
	</tbody>
</table></form></div>
{% else %}
	<p>{% trans %}Currently, there are no pending invitations.{% endtrans %}</p>
{% endif %}
{% endblock %}
