{% include 'mcp_header.html' %}

<div class="iz-mcp">

	<form id="mcp" method="post" action="{{ S_MCP_ACTION }}" class="iz-form">

		<header class="iz-pagehead" aria-labelledby="iz-mcp-queue-title">
			<h2 class="iz-pagehead__title" id="iz-mcp-queue-title">{{ L_TITLE }}</h2>
			<p class="iz-pagehead__lead">{{ L_EXPLAIN }}</p>
		</header>

		<section class="iz-card iz-card--mcp" aria-labelledby="iz-queue-filter-title">
			<header class="iz-card__header">
				<h3 class="iz-card__title" id="iz-queue-filter-title">{{ L_OPTIONS }}</h3>
			</header>

			<div class="iz-card__body">
				<div class="iz-grid iz-grid--2">
					<div class="iz-field">
						<label class="iz-label" for="fo">{{ L_FORUM }}{{ L_COLON }}</label>
						<div class="iz-field__row iz-field__row--actions">
							<select class="iz-select" name="f" id="fo">
								{{ S_FORUM_OPTIONS }}
							</select>
							<button class="iz-btn iz-btn--primary" type="submit" name="sort" value="{{ L_GO }}">
								{{ L_GO }}
							</button>
						</div>
						{{ S_FORM_TOKEN }}
					</div>

					<div class="iz-field">
						<div class="iz-field__row iz-field__row--actions iz-field__row--end">
							<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 }}</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>
				</div>
			</div>
		</section>


		{% if postrow %}
			<section class="iz-card iz-card--mcp" aria-labelledby="iz-queue-title">
				<header class="iz-card__header">
					<h3 class="iz-card__title" id="iz-queue-title">{{ L_QUEUE }}</h3>
				</header>

				<div class="iz-card__body">
					<div class="iz-table" role="region" aria-label="{{ L_QUEUE }}">
						<table 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">
										{% if S_TOPICS %}{{ L_TOPIC }}{% else %}{{ L_POST }}{% endif %}
									</th>
									<th scope="col" class="iz-table__th">
										{% if not S_TOPICS %}{{ L_TOPIC }}&nbsp;{% endif %}{{ L_FORUM }}
									</th>
									<th scope="col" class="iz-table__th">
										<span class="iz-visually-hidden">{{ L_MARK }}</span>
										{{ L_MARK }}
									</th>
								</tr>
							</thead>

							<tbody class="iz-table__body">
								{% for postrow in postrow %}

									{% if postrow.S_DELETED_TOPIC %}
										<tr class="iz-table__row">
											<td class="iz-table__td" colspan="3">
												<p class="iz-alert iz-alert--info" role="status">{{ L_DELETED_TOPIC }}</p>
											</td>
										</tr>
									{% else %}
										<tr class="iz-table__row">
											<td class="iz-table__td">
												<a class="iz-link iz-link--strong" href="{{ postrow.U_VIEW_DETAILS }}">
													{{ postrow.POST_SUBJECT }}
												</a>

												<p class="iz-help">
													{% if postrow.S_HAS_ATTACHMENTS %}
														<span class="iz-badge" title="{{ L_ATTACH_FORUM }}">{{ L_ATTACHMENTS }}</span>&nbsp;
													{% endif %}
													{{ L_POST_BY_AUTHOR }}&nbsp;{{ postrow.POST_AUTHOR_FULL }}
													&nbsp;&raquo;&nbsp;<time>{{ postrow.POST_TIME }}</time>
												</p>
											</td>

											<td class="iz-table__td">
												<p class="iz-help">
													{% if S_TOPICS %}
														{{ L_TOPIC }}{{ L_COLON }}&nbsp;<a class="iz-link" href="{{ postrow.U_TOPIC }}">{{ postrow.TOPIC_TITLE }}</a><br />
													{% endif %}
													{{ L_FORUM }}{{ L_COLON }}&nbsp;<a class="iz-link" href="{{ postrow.U_VIEWFORUM }}">{{ postrow.FORUM_NAME }}</a>
												</p>
											</td>

											<td class="iz-table__td">
												<label class="iz-choice" for="mark_{{ postrow.POST_ID }}">
													{% if S_TOPICS %}
														<input class="iz-choice__input"
															   type="checkbox"
															   name="topic_id_list[]"
															   value="{{ postrow.TOPIC_ID }}"
															   id="mark_{{ postrow.TOPIC_ID }}" />
													{% else %}
														<input class="iz-choice__input"
															   type="checkbox"
															   name="post_id_list[]"
															   value="{{ postrow.POST_ID }}"
															   id="mark_{{ postrow.POST_ID }}" />
													{% endif %}
													<span class="iz-choice__label">{{ L_MARK }}</span>
												</label>
											</td>
										</tr>
									{% endif %}

								{% endfor %}
							</tbody>
						</table>
					</div>

					<hr class="iz-hr" />

					<div class="iz-toolbar" role="region" aria-label="{{ L_OPTIONS }}">
						<div class="iz-toolbar__left">
							{% if TOPIC_ID %}
								<label class="iz-choice" for="t">
									<input class="iz-choice__input"
										   type="checkbox"
										   name="t"
										   id="t"
										   value="{{ TOPIC_ID }}"
										   checked="checked" />
									<span class="iz-choice__label">{{ L_ONLY_TOPIC }}</span>
								</label>
							{% endif %}
						</div>

						<div class="iz-toolbar__right">
							<fieldset class="iz-actions iz-actions--inline" aria-label="{{ L_OPTIONS }}">
								{% if S_RESTORE %}
									<button class="iz-btn iz-btn--danger" type="submit" name="action[delete]" value="{{ L_DELETE }}" title="{{ L_DELETE }}">
										{{ L_DELETE }}
									</button>
									<button class="iz-btn iz-btn--primary" type="submit" name="action[restore]" value="{{ L_RESTORE }}" title="{{ L_RESTORE }}">
										{{ L_RESTORE }}
									</button>
								{% else %}
									<button class="iz-btn iz-btn--primary" type="submit" name="action[approve]" value="{{ L_APPROVE }}" title="{{ L_APPROVE }}">
										{{ L_APPROVE }}
									</button>
									<button class="iz-btn iz-btn--secondary" type="submit" name="action[disapprove]" value="{{ L_DISAPPROVE }}" title="{{ L_DISAPPROVE }}">
										{{ L_DISAPPROVE }}
									</button>
								{% endif %}

								<span class="iz-actions__sep" aria-hidden="true"></span>

								{% if S_TOPICS %}
									<button class="iz-btn iz-btn--secondary"
											type="button"
											onclick="marklist('mcp', 'topic_id_list', true); return false;">
										{{ L_MARK_ALL }}
									</button>
									<button class="iz-btn iz-btn--secondary"
											type="button"
											onclick="marklist('mcp', 'topic_id_list', false); return false;">
										{{ L_UNMARK_ALL }}
									</button>
								{% else %}
									<button class="iz-btn iz-btn--secondary"
											type="button"
											onclick="marklist('mcp', 'post_id_list', true); return false;">
										{{ L_MARK_ALL }}
									</button>
									<button class="iz-btn iz-btn--secondary"
											type="button"
											onclick="marklist('mcp', 'post_id_list', false); return false;">
										{{ L_UNMARK_ALL }}
									</button>
								{% endif %}
							</fieldset>
						</div>
					</div>

					<div class="iz-toolbar" role="region" aria-label="{{ L_PAGINATION }}">
						<div class="iz-toolbar__left"></div>
						<div class="iz-toolbar__right">
							<nav class="iz-pagination" aria-label="{{ L_PAGINATION }}">
								<ul class="iz-pagination__list">
									<li class="iz-pagination__item">
										<span class="iz-pagination__meta">{{ TOTAL }}</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 'display_options.html' %}
				</div>
			</section>

		{% else %}
			<p class="iz-alert iz-alert--info" role="status">
				{% if S_RESTORE %}
					{% if S_TOPICS %}{{ L_NO_TOPICS_DELETED }}{% else %}{{ L_NO_POSTS_DELETED }}{% endif %}
				{% else %}
					{% if S_TOPICS %}{{ L_NO_TOPICS_QUEUE }}{% else %}{{ L_NO_POSTS_QUEUE }}{% endif %}
				{% endif %}
			</p>
		{% endif %}

	</form>

	<script>
	(function () {
		'use strict';

		// Preserve behavior of the legacy "Only topic" toggle without iCheck/head.js dependencies.
		document.addEventListener('DOMContentLoaded', function () {
			var onlyTopic = document.getElementById('t');
			var form = document.getElementById('mcp');
			if (!onlyTopic || !form) return;

			onlyTopic.addEventListener('change', function () {
				// Legacy behavior: when unchecked, submit to refresh queue view.
				if (!onlyTopic.checked) form.submit();
			});
		});
	})();
	</script>

</div>

{% include 'mcp_footer.html' %}
