{% include 'ucp_header.html' %}

<div class="tab-pane active">
	<form id="ucp" method="post" action="{{ S_UCP_ACTION }}" class="iz-form">

		<section class="iz-card iz-card--ucp iz-card--pm-options">
			<header class="iz-card__header">
				<h2 class="iz-card__title">{{ L_TITLE }}</h2>
			</header>

			<div class="iz-card__body">

				{% if ERROR %}
					<div class="iz-alert iz-alert--info" role="status">
						<strong>{{ L_INFO_BOX }}</strong>&nbsp;{{ ERROR_MESSAGE }}
					</div>
					<div class="iz-space iz-space--sm"></div>
				{% endif %}

				{% if NOTIFICATION_MESSAGE %}
					<div class="iz-alert iz-alert--danger" role="status">
						{{ NOTIFICATION_MESSAGE }}
					</div>
					<div class="iz-space iz-space--sm"></div>
				{% endif %}


				<!-- Defined rules -->
				<section class="iz-card iz-card--nested" aria-label="{{ L_DEFINED_RULES }}">
					<header class="iz-card__header">
						<h3 class="iz-card__title">{{ L_DEFINED_RULES }}</h3>
					</header>

					<div class="iz-card__body">
						<ul class="iz-list iz-list--rules">
							{% for rule in rule %}
								<li class="iz-list__item">
									<div class="iz-ruleline">
										<div class="iz-ruleline__text">
											<strong>{{ L_IF }}</strong>&nbsp;{{ rule.CHECK }}
											<em>&nbsp;{{ rule.RULE }}</em>
											{% if rule.STRING %}
												<strong>&nbsp;{{ rule.STRING }}</strong>&nbsp;<span class="iz-sep">•</span>
											{% endif %}
											{{ rule.ACTION }}{% if rule.FOLDER %}{{ L_COLON }}&nbsp;{{ rule.FOLDER }}{% endif %}
										</div>

										<div class="iz-ruleline__actions">
											<button
												class="iz-btn iz-btn--danger iz-btn--xs"
												name="delete_rule[{{ rule.RULE_ID }}]"
												type="submit"
												title="{{ L_DELETE_RULE }}">
												{{ L_DELETE_RULE }}
											</button>
										</div>
									</div>
								</li>
							<!-- BEGINELSE -->
								<li class="iz-list__item">
									<div class="iz-meta iz-meta--small">{{ L_NO_RULES_DEFINED }}</div>
								</li>
							{% endfor %}
						</ul>
					</div>
				</section>

				<div class="iz-space iz-space--md"></div>


				<!-- Add new rule (multi-step builder) -->
				<section class="iz-card iz-card--nested" aria-label="{{ L_ADD_NEW_RULE }}">
					<header class="iz-card__header">
						<h3 class="iz-card__title">{{ L_ADD_NEW_RULE }}</h3>
					</header>

					<div class="iz-card__body">

						<div class="iz-fieldgroup">

							{% if S_CHECK_DEFINED %}
								<div class="iz-field">
									<div class="iz-field__label">{{ L_IF }}{{ L_COLON }}</div>

									{% if S_CHECK_SELECT %}
										<div class="iz-field__control">
											<select name="check_option" id="check_option" class="iz-select">
												{{ S_CHECK_OPTIONS }}
											</select>
										</div>

										<div class="iz-field__actions">
											<button class="iz-btn iz-btn--ghost iz-btn--sm" name="next" type="submit">
												{{ L_NEXT_STEP }}
											</button>
										</div>
									{% else %}
										<div class="iz-field__control">
											<span class="iz-meta">{{ CHECK_CURRENT }}</span>
											<input type="hidden" name="check_option" value="{{ CHECK_OPTION }}" />
										</div>
									{% endif %}
								</div>
							{% endif %}


							{% if S_RULE_DEFINED %}
								<div class="iz-field">
									<div class="iz-field__label">{{ L_RULE }}{{ L_COLON }}</div>

									{% if S_RULE_SELECT %}
										<div class="iz-field__control">
											<select name="rule_option" id="rule_option" class="iz-select">
												{{ S_RULE_OPTIONS }}
											</select>
										</div>

										<div class="iz-field__actions">
											<button class="iz-btn iz-btn--ghost iz-btn--sm" name="back[rule]" type="submit">
												{{ L_PREVIOUS_STEP }}
											</button>
											<button class="iz-btn iz-btn--ghost iz-btn--sm" name="next" type="submit">
												{{ L_NEXT_STEP }}
											</button>
										</div>
									{% else %}
										<div class="iz-field__control">
											<span class="iz-meta">{{ RULE_CURRENT }}</span>
											<input type="hidden" name="rule_option" value="{{ RULE_OPTION }}" />
										</div>
									{% endif %}
								</div>
							{% endif %}


							{% if S_COND_DEFINED %}
								<div class="iz-field">
									<div class="iz-field__label">{{ L_CONDITION }}{{ L_COLON }}</div>

									{% if S_COND_SELECT or COND_CURRENT %}
										{% if S_COND_SELECT %}
											<div class="iz-field__control">
												{% if S_TEXT_CONDITION %}
													<input class="iz-input" name="rule_string" value="{{ CURRENT_STRING }}" type="text" maxlength="50" />
												{% elseif S_USER_CONDITION %}
													<div class="iz-row iz-row--wrap iz-row--gap-sm">
														<input class="iz-input" name="rule_string" value="{{ CURRENT_STRING }}" type="text" maxlength="50" />
														<span class="iz-meta iz-meta--small">
															&#91;&nbsp;<a class="iz-link" href="{{ U_FIND_USERNAME }}" onclick="find_username(this.href); return false;">{{ L_FIND_USERNAME }}</a>&nbsp;&#93;
														</span>
													</div>
												{% elseif S_GROUP_CONDITION %}
													<input type="hidden" name="rule_string" value="{{ CURRENT_STRING }}" />
													{% if S_GROUP_OPTIONS %}
														<select class="iz-select" name="rule_group_id">
															{{ S_GROUP_OPTIONS }}
														</select>
													{% else %}
														<span class="iz-meta">{{ L_NO_GROUPS }}</span>
													{% endif %}
												{% endif %}
											</div>

											<div class="iz-field__actions">
												<button class="iz-btn iz-btn--ghost iz-btn--sm" name="back[cond]" type="submit">
													{{ L_PREVIOUS_STEP }}
												</button>
												<button class="iz-btn iz-btn--ghost iz-btn--sm" name="next" type="submit">
													{{ L_NEXT_STEP }}
												</button>
											</div>
										{% else %}
											<div class="iz-field__control">
												<span class="iz-meta">{{ COND_CURRENT }}</span>
												<input type="hidden" name="rule_string" value="{{ CURRENT_STRING }}" />
												<input type="hidden" name="rule_user_id" value="{{ CURRENT_USER_ID }}" />
												<input type="hidden" name="rule_group_id" value="{{ CURRENT_GROUP_ID }}" />
											</div>
										{% endif %}
									{% endif %}

									<input type="hidden" name="cond_option" value="{{ COND_OPTION }}" />
								</div>
							{% endif %}

							{% if NONE_CONDITION %}
								<input type="hidden" name="cond_option" value="none" />
							{% endif %}


							{% if S_ACTION_DEFINED %}
								<div class="iz-field">
									<div class="iz-field__label">{{ L_ACTION }}{{ L_COLON }}</div>

									{% if S_ACTION_SELECT %}
										<div class="iz-field__control">
											<select class="iz-select" name="action_option">
												{{ S_ACTION_OPTIONS }}
											</select>
										</div>

										<div class="iz-field__actions">
											<button class="iz-btn iz-btn--ghost iz-btn--sm" name="back[action]" type="submit">
												{{ L_PREVIOUS_STEP }}
											</button>
											<button class="iz-btn iz-btn--primary iz-btn--sm" name="add_rule" type="submit">
												{{ L_ADD_RULE }}
											</button>
										</div>
									{% else %}
										<div class="iz-field__control">
											<span class="iz-meta">{{ ACTION_CURRENT }}</span>
											<input type="hidden" name="action_option" value="{{ ACTION_OPTION }}" />
										</div>
									{% endif %}
								</div>
							{% endif %}

						</div>
					</div>
				</section>

				<div class="iz-space iz-space--md"></div>


				<!-- Folder options -->
				<section class="iz-card iz-card--nested" aria-label="{{ L_FOLDER_OPTIONS }}">
					<header class="iz-card__header">
						<h3 class="iz-card__title">{{ L_FOLDER_OPTIONS }}</h3>
					</header>

					<div class="iz-card__body">

						<!-- Add folder -->
						{% if not S_MAX_FOLDER_ZERO %}
							<div class="iz-fieldgroup">
								<div class="iz-field">
									<label class="iz-field__label" for="foldername">{{ L_ADD_FOLDER }}{{ L_COLON }}</label>

									{% if S_MAX_FOLDER_REACHED %}
										<div class="iz-meta">{{ L_MAX_FOLDER_REACHED }}</div>
									{% else %}
										<div class="iz-field__control">
											<input class="iz-input" type="text" name="foldername" id="foldername" maxlength="30" />
										</div>
										<div class="iz-field__actions">
											<button type="submit" name="addfolder" class="iz-btn iz-btn--ghost iz-btn--sm">
												{{ L_ADD }}
											</button>
										</div>
									{% endif %}
								</div>
							</div>

							{% if S_FOLDER_OPTIONS %}
								<div class="iz-separator"></div>
							{% endif %}
						{% endif %}


						<!-- Rename / remove folder -->
						{% if S_FOLDER_OPTIONS %}

							<div class="iz-fieldgroup">
								<div class="iz-field">
									<label class="iz-field__label" for="rename_folder_id">{{ L_RENAME_FOLDER }}{{ L_COLON }}</label>
									<div class="iz-field__control">
										<select class="iz-select" name="rename_folder_id" id="rename_folder_id">
											{{ S_FOLDER_OPTIONS }}
										</select>
									</div>
								</div>

								<div class="iz-field">
									<label class="iz-field__label" for="new_folder_name">{{ L_NEW_FOLDER_NAME }}</label>
									<div class="iz-field__control">
										<input class="iz-input" type="text" name="new_folder_name" id="new_folder_name" maxlength="30" placeholder="{{ L_NEW_FOLDER_NAME }}" />
									</div>
									<div class="iz-field__actions">
										<button type="submit" name="rename_folder" class="iz-btn iz-btn--ghost iz-btn--sm">
											{{ L_RENAME }}
										</button>
									</div>
								</div>
							</div>

							<div class="iz-separator"></div>

							<div class="iz-fieldgroup">
								<div class="iz-field">
									<label class="iz-field__label" for="remove_folder_id">{{ L_REMOVE_FOLDER }}{{ L_COLON }}</label>
									<div class="iz-field__control">
										<select class="iz-select" name="remove_folder_id" id="remove_folder_id">
											{{ S_FOLDER_OPTIONS }}
										</select>
									</div>
								</div>

								<div class="iz-field">
									<div class="iz-field__label">{{ L_REMOVE_FOLDER }}{{ L_COLON }}</div>
									<div class="iz-field__control">

										<div class="iz-choice iz-choice--radio">
											<input type="radio" name="remove_action" id="remove_action1" value="1" checked="checked" />
											<label for="remove_action1">{{ L_MOVE_DELETED_MESSAGES_TO }}{{ L_COLON }}</label>
										</div>

										<div class="iz-space iz-space--xs"></div>

										<select class="iz-select" name="move_to">
											{{ S_TO_FOLDER_OPTIONS }}
										</select>

										<div class="iz-space iz-space--sm"></div>

										<div class="iz-choice iz-choice--radio">
											<input type="radio" name="remove_action" id="remove_action2" value="2" />
											<label for="remove_action2">{{ L_DELETE_MESSAGES_IN_FOLDER }}</label>
										</div>

									</div>

									<div class="iz-field__actions">
										<button type="submit" name="remove_folder" class="iz-btn iz-btn--ghost iz-btn--sm">
											{{ L_UCP_APPLY }}
										</button>
									</div>
								</div>
							</div>

							<div class="iz-separator"></div>

						{% endif %}


						<!-- Folder full behavior -->
						<div class="iz-fieldgroup">
							<div class="iz-field">
								<div class="iz-field__label">{{ L_IF_FOLDER_FULL }}{{ L_COLON }}</div>
								<div class="iz-field__control">

									<div class="iz-choice iz-choice--radio">
										<input type="radio" name="full_action" id="full_action3" value="3"{{ S_HOLD_CHECKED }} />
										<label for="full_action3">
											{{ L_UCP_PM_DEFAULT_RULE }}
											<span class="iz-badge iz-badge--muted">{{ L_UCP_PM_DEFAULT_RULE_TAG }}</span>
										</label>
									</div>

									<div class="iz-choice iz-choice--radio">
										<input type="radio" name="full_action" id="full_action1" value="1"{{ S_DELETE_CHECKED }} />
										<label for="full_action1">{{ L_DELETE_OLDEST_MESSAGES }}</label>
									</div>

									<div class="iz-choice iz-choice--radio">
										<input type="radio" name="full_action" id="full_action2" value="2"{{ S_MOVE_CHECKED }} />
										<label for="full_action2">{{ L_MOVE_TO_FOLDER }}{{ L_COLON }}</label>
									</div>

									<div class="iz-space iz-space--xs"></div>

									<select class="iz-select" name="full_move_to">
										{{ S_FULL_FOLDER_OPTIONS }}
									</select>

								</div>
							</div>

							<div class="iz-alert iz-alert--info" role="note">
								<strong>{{ L_DEFAULT_ACTION }}{{ L_COLON }}</strong>&nbsp;{{ L_UCP_PM_DEFAULT_RULE_EXPLAIN }}
							</div>

							<div class="iz-actions">
								<button type="submit" name="fullfolder" class="iz-btn iz-btn--ghost iz-btn--sm">
									{{ L_CHANGE }}
								</button>
							</div>
						</div>

					</div>
				</section>

				{{ S_FORM_TOKEN }}

			</div>
		</section>

	</form>
</div>

{% include 'ucp_footer.html' %}
