{% if S_IN_SEARCH_POPUP %}
	{% include 'simple_header_ACP.html' %}
	{% include 'memberlist_search.html' %}
	<form method="post"
		  id="results"
		  action="{{ S_MODE_ACTION }}"
		  onsubmit="insert_marked_users('#results', this.user); return false;"
		  data-form-name="{{ S_FORM_NAME }}"
		  data-field-name="{{ S_FIELD_NAME }}"
		  class="iz-form">

{% elseif S_SEARCH_USER %}
	{% include 'overall_header.html' %}
	{% include 'memberlist_search.html' %}
	<form method="post" action="{{ S_MODE_ACTION }}" class="iz-form">

{% else %}
	{% include 'overall_header.html' %}
	<form method="post" action="{{ S_MODE_ACTION }}" class="iz-form">
{% endif %}

<div class="iz-page">

	{% if S_SHOW_GROUP %}
		<header class="iz-pagehead" aria-labelledby="iz-group-title">
			<h2 class="iz-pagehead__title" id="iz-group-title"{% if GROUP_COLOR %} style="color:#{{ GROUP_COLOR }};"{% endif %}>{{ GROUP_NAME }}</h2>

			{% if U_MANAGE %}
				<p class="iz-pagehead__actions">
					<a class="iz-btn iz-btn--secondary" href="{{ U_MANAGE }}">{{ L_MANAGE_GROUP }}</a>
				</p>
			{% endif %}

			<div class="iz-prose">
				<p>{{ GROUP_DESC }}&nbsp;{{ GROUP_TYPE }}</p>
				{% if AVATAR_IMG %}{{ AVATAR_IMG }}{% endif %}
				{% if RANK_IMG %}{{ RANK_IMG }}{% endif %}
				{% if GROUP_RANK %}{{ GROUP_RANK }}{% endif %}
			</div>
		</header>

	{% else %}
		<header class="iz-pagehead" aria-labelledby="iz-memberlist-title">
			<h2 class="iz-pagehead__title" id="iz-memberlist-title">
				{{ PAGE_TITLE }}
				{% if SEARCH_WORDS %}
					{{ L_COLON }}&nbsp;<a class="iz-link" href="{{ U_SEARCH_WORDS }}">{{ SEARCH_WORDS }}</a>
				{% endif %}
			</h2>

			<div class="iz-toolbar" role="region" aria-label="{{ L_OPTIONS }}">
				<div class="iz-toolbar__left">
					<nav class="iz-alpha" aria-label="{{ L_SORT_USERNAME }}">
						<ul class="iz-alpha__list">
							{% if U_FIND_MEMBER and not S_SEARCH_USER %}
								<li class="iz-alpha__item"><a class="iz-alpha__link" href="{{ U_FIND_MEMBER }}">{{ L_FIND_USERNAME }}</a></li>
							{% elseif S_SEARCH_USER and U_HIDE_FIND_MEMBER and not S_IN_SEARCH_POPUP %}
								<li class="iz-alpha__item"><a class="iz-alpha__link" href="{{ U_HIDE_FIND_MEMBER }}">{{ L_HIDE_MEMBER_SEARCH }}</a></li>
							{% endif %}

							{% for first_char in first_char %}
								<li class="iz-alpha__item">
									<a class="iz-alpha__link" href="{{ first_char.U_SORT }}">{{ first_char.DESC }}</a>
								</li>
							{% endfor %}
						</ul>
					</nav>
				</div>

				{% if S_IN_SEARCH_POPUP %}
				<div class="iz-toolbar__right">
					<nav class="iz-pagination iz-pagination--compact" aria-label="{{ L_PAGINATION }}">
						<ul class="iz-pagination__list">
							<li class="iz-pagination__item"><span class="iz-pagination__meta">{{ TOTAL_USERS }}</span></li>
							{% if pagination %}
								{% include 'pagination.html' %}
							{% else %}
								<li class="iz-pagination__item"><span class="iz-pagination__current" aria-current="page">{{ PAGE_NUMBER }}</span></li>
							{% endif %}
						</ul>
					</nav>
				</div>
				{% endif %}
			</div>
		</header>
	{% endif %}


	<!-- We keep the legacy conditional that decides whether to open the first members table wrapper -->
	{% if S_LEADERS_SET or not S_SHOW_GROUP or not .memberrow %}
	<section class="iz-card iz-card--mcp" aria-labelledby="iz-members-title">
		<header class="iz-card__header">
			<h3 class="iz-card__title" id="iz-members-title">{{ L_MEMBERS }}</h3>
		</header>

		<div class="iz-card__body">
			<div class="iz-table" role="region" aria-label="{{ L_MEMBERS }}">
				<table id="memberlist" class="iz-table__table">
					<thead class="iz-table__head">
						<tr class="iz-table__row">
							<th scope="col" class="iz-table__th iz-table__th--grow">
								<a class="iz-link" href="{{ U_SORT_USERNAME }}">
									{% if S_SHOW_GROUP and .memberrow %}{{ L_GROUP_LEADER }}{% else %}{{ L_USERNAME }}{% endif %}
								</a>
								{{ L_COMMA_SEPARATOR }}
								<a class="iz-link" href="{{ U_SORT_RANK }}">{{ L_RANK }}</a>
							</th>
							<th scope="col" class="iz-table__th">
								<a class="iz-link" href="{{ U_SORT_POSTS }}#memberlist">{{ L_POSTS }}</a>
							</th>
							<th scope="col" class="iz-table__th">{{ L_OTHER }}</th>
							<th scope="col" class="iz-table__th">
								<a class="iz-link" href="{{ U_SORT_JOINED }}#memberlist">{{ L_JOINED }}</a>
							</th>
							{% if U_SORT_ACTIVE %}
								<th scope="col" class="iz-table__th">
									<a class="iz-link" href="{{ U_SORT_ACTIVE }}#memberlist">{{ L_LAST_ACTIVE }}</a>
								</th>
							{% endif %}
						</tr>
					</thead>
					<tbody class="iz-table__body">
	{% endif %}


	{% for memberrow in memberrow %}

		{% if S_SHOW_GROUP %}
			{% if not memberrow.S_GROUP_LEADER and not $S_MEMBER_HEADER %}
				{% if S_LEADERS_SET and memberrow.S_FIRST_ROW %}
					<tr class="iz-table__row">
						<td class="iz-table__td" colspan="{% if U_SORT_ACTIVE %}5{% else %}4{% endif %}">&nbsp;</td>
					</tr>
				{% endif %}

				{% if S_LEADERS_SET %}
					</tbody>
				</table>
			</div>
		</div>
	</section>
				{% endif %}

				<section class="iz-card iz-card--mcp" aria-labelledby="iz-members-secondary-title">
					<header class="iz-card__header">
						<h3 class="iz-card__title" id="iz-members-secondary-title">{{ L_MEMBERS }}</h3>
					</header>

					<div class="iz-card__body">
						<div class="iz-table" role="region" aria-label="{{ L_MEMBERS }}">
							<table class="iz-table__table">
								<thead class="iz-table__head">
									<tr class="iz-table__row">
										{% if not S_LEADERS_SET %}
											<th scope="col" class="iz-table__th iz-table__th--grow">
												<a class="iz-link" href="{{ U_SORT_USERNAME }}">{{ L_GROUP_MEMBERS }}</a>
												<span class="iz-meta">
													{{ L_COMMA_SEPARATOR }}<a class="iz-link" href="{{ U_SORT_RANK }}">{{ L_RANK }}</a>
												</span>
											</th>
											<th scope="col" class="iz-table__th">
												<a class="iz-link" href="{{ U_SORT_POSTS }}#memberlist">{{ L_POSTS }}</a>
											</th>
											<th scope="col" class="iz-table__th">{{ L_OTHER }}</th>
											<th scope="col" class="iz-table__th">
												<a class="iz-link" href="{{ U_SORT_JOINED }}#memberlist">{{ L_JOINED }}</a>
											</th>
											{% if U_SORT_ACTIVE %}
												<th scope="col" class="iz-table__th">
													<a class="iz-link" href="{{ U_SORT_ACTIVE }}#memberlist">{{ L_LAST_ACTIVE }}</a>
												</th>
											{% endif %}
										{% elseif S_SHOW_GROUP %}
											<th scope="col" class="iz-table__th iz-table__th--grow">{{ L_GROUP_MEMBERS }}</th>
											<th scope="col" class="iz-table__th">&nbsp;</th>
											<th scope="col" class="iz-table__th">&nbsp;</th>
											<th scope="col" class="iz-table__th">&nbsp;</th>
											{% if U_SORT_ACTIVE %}<th scope="col" class="iz-table__th">&nbsp;</th>{% endif %}
										{% endif %}
									</tr>
								</thead>
								<tbody class="iz-table__body">
									{% set S_MEMBER_HEADER = 1 %}
			{% endif %}
		{% endif %}

		<tr class="iz-table__row">
			<td class="iz-table__td">
				{% if S_IN_SEARCH_POPUP and not S_SELECT_SINGLE %}
					<label class="iz-choice" for="user_{{ memberrow.A_USERNAME }}">
						<input class="iz-choice__input" type="checkbox" name="user" id="user_{{ memberrow.A_USERNAME }}" value="{{ memberrow.USERNAME }}" />
						<span class="iz-choice__label">{{ L_MARK }}</span>
					</label>
				{% endif %}

				{% EVENT memberlist_body_username_prepend %}
				{{ memberrow.USERNAME_FULL }}
				{% EVENT memberlist_body_username_append %}

				{% if S_IN_SEARCH_POPUP %}
					&nbsp;&#91;&nbsp;
					<a class="iz-link iz-link--strong"
					   href="#"
					   onclick="insert_single_user('#results', '{{ memberrow.A_USERNAME }}'); return false;">
						{{ L_SELECT }}
					</a>
					&nbsp;&#93;
				{% endif %}

				{% if memberrow.S_INACTIVE %}
					&nbsp;&#40;{{ L_INACTIVE }}&#41;
				{% endif %}

				<br />

				{% EVENT memberlist_body_rank_prepend %}
				{% if memberrow.RANK_IMG %}
					<span class="rank-img">{{ memberrow.RANK_IMG }}</span>
					{% EVENT memberlist_body_rank_append %}
				{% else %}
					<span class="iz-meta">{{ memberrow.RANK_TITLE }}</span>
				{% endif %}
			</td>

			<td class="iz-table__td">
				{% if memberrow.POSTS and S_DISPLAY_SEARCH %}
					<a class="iz-link" href="{{ memberrow.U_SEARCH_USER }}" title="{{ L_SEARCH_USER_POSTS }}">{{ memberrow.POSTS }}</a>
				{% else %}
					{{ memberrow.POSTS }}
				{% endif %}
			</td>

			<td class="iz-table__td">
				<!-- Contact-style custom fields -->
				{% for custom_fields in custom_fields %}
					{% if memberrow.custom_fields.S_PROFILE_CONTACT %}
						{% if memberrow.custom_fields.PROFILE_FIELD_CONTACT %}
							<a class="iz-link"
							   href="{{ memberrow.custom_fields.PROFILE_FIELD_CONTACT }}"
							   title="{{ memberrow.custom_fields.PROFILE_FIELD_DESC }}">
								{{ memberrow.custom_fields.PROFILE_FIELD_NAME }}
							</a>&nbsp;
						{% endif %}
					{% endif %}
				{% endfor %}

				<!-- Non-contact custom fields -->
				{% for custom_fields in custom_fields %}
					{% if not memberrow.custom_fields.S_PROFILE_CONTACT %}
						{{ memberrow.custom_fields.PROFILE_FIELD_VALUE }}&#44;&nbsp;
					{% endif %}
				{% endfor %}
			</td>

			<td class="iz-table__td"><time>{{ memberrow.JOINED }}</time></td>

			{% if S_VIEWONLINE %}
				<td class="iz-table__td"><time>{{ memberrow.LAST_ACTIVE }}</time></td>
			{% endif %}
		</tr>

	<!-- BEGINELSE -->
		<tr class="iz-table__row">
			<td class="iz-table__td" colspan="{% if S_VIEWONLINE %}5{% else %}4{% endif %}">{{ L_NO_MEMBERS }}</td>
		</tr>
	{% endfor %}

	</tbody>
	</table>
	</div>
	</div>
	</section>


	<!-- Popup multi-select controls -->
	{% if S_IN_SEARCH_POPUP and not S_SELECT_SINGLE %}
		<div class="iz-toolbar" role="region" aria-label="{{ L_OPTIONS }}">
			<div class="iz-toolbar__left">
				<fieldset class="iz-actions iz-actions--inline">
					<button class="iz-btn iz-btn--secondary" type="button" onclick="marklist('results', 'user', true); return false;">
						{{ L_MARK_ALL }}
					</button>
					<button class="iz-btn iz-btn--secondary" type="button" onclick="marklist('results', 'user', false); return false;">
						{{ L_UNMARK_ALL }}
					</button>
					<button class="iz-btn iz-btn--primary" type="submit" title="{{ L_SELECT_MARKED }}">
						{{ L_SELECT_MARKED }}
					</button>
				</fieldset>
			</div>
			<div class="iz-toolbar__right"></div>
		</div>
	{% endif %}


	{% if S_IN_SEARCH_POPUP %}
		</form>
		<form method="post" id="sort-results" action="{{ S_MODE_ACTION }}" class="iz-form">

		<div class="iz-toolbar" role="region" aria-label="{{ L_SELECT_SORT_METHOD }}">
			<div class="iz-toolbar__left">
				<div class="iz-field">
					<label class="iz-label" for="sk">{{ L_SELECT_SORT_METHOD }}{{ L_COLON }}</label>
					<div class="iz-field__row iz-field__row--actions">
						<select class="iz-select" name="sk" id="sk">{{ S_MODE_SELECT }}</select>
						<select class="iz-select" name="sd" id="sd">{{ S_ORDER_SELECT }}</select>
						<button type="submit" name="sort" value="{{ L_SUBMIT }}" class="iz-btn iz-btn--primary">{{ L_SUBMIT }}</button>
					</div>
				</div>
			</div>

			<div class="iz-toolbar__right">
				<nav class="iz-pagination iz-pagination--compact" aria-label="{{ L_PAGINATION }}">
					<ul class="iz-pagination__list">
						<li class="iz-pagination__item"><span class="iz-pagination__meta">{{ TOTAL_USERS }}</span></li>
						{% if pagination %}
							{% include 'pagination.html' %}
						{% else %}
							<li class="iz-pagination__item"><span class="iz-pagination__current" aria-current="page">{{ PAGE_NUMBER }}</span></li>
						{% endif %}
					</ul>
				</nav>
			</div>
		</div>

		</form>

		{% include 'simple_footer.html' %}

	{% else %}
		</form>

		<div class="iz-toolbar" role="region" aria-label="{{ L_PAGINATION }}">
			<div class="iz-toolbar__left">
				{% include 'jumpbox_options.html' %}
			</div>

			<div class="iz-toolbar__right">
				<nav class="iz-pagination iz-pagination--compact" aria-label="{{ L_PAGINATION }}">
					<ul class="iz-pagination__list">
						<li class="iz-pagination__item"><span class="iz-pagination__meta">{{ TOTAL_USERS }}</span></li>
						{% if pagination %}
							{% include 'pagination.html' %}
						{% else %}
							<li class="iz-pagination__item"><span class="iz-pagination__current" aria-current="page">{{ PAGE_NUMBER }}</span></li>
						{% endif %}
					</ul>
				</nav>
			</div>
		</div>

		{% include 'jump_links.html' %}
		{% include 'overall_footer.html' %}
	{% endif %}

</div>
