<xf:if is="$forum.isInsert()">
	<xf:title>{{ phrase('add_forum') }}</xf:title>
<xf:else />
	<xf:title>{{ phrase('edit_forum:') }} {$node.title}</xf:title>
</xf:if>

<xf:pageaction if="$forum.isUpdate()">
	<div class="buttonGroup">
		<xf:if is="$canChangeForumType">
			<xf:button href="{{ link('forums/change-type', $node) }}" overlay="true">{{ phrase('change_type') }}</xf:button>
		</xf:if>
		<xf:button href="{{ link('forums/delete', $node) }}" icon="delete" overlay="true" />
	</div>
</xf:pageaction>

<xf:form action="{{ link('forums/save', $node) }}" ajax="true" class="block">
	<div class="block-container">
		<div class="block-body">
			<xf:macro template="node_edit_macros" name="title" arg-node="{$node}" />
			<xf:macro template="node_edit_macros" name="description" arg-node="{$node}" />

			<hr class="formRowSep" />
			<xf:macro template="node_edit_macros" name="node_name" arg-node="{$node}" />
			<xf:macro template="node_edit_macros" name="position" arg-node="{$node}" arg-nodeTree="{$nodeTree}" />
			<xf:macro template="node_edit_macros" name="navigation" arg-node="{$node}" arg-navChoices="{$navChoices}" />
			<hr class="formRowSep" />

			<xf:formrow label="{{ phrase('forum_type') }}" explain="{$forumTypeDesc}"><span>{$forumTypeTitle}</span></xf:formrow>
			<xf:if is="$typeConfigTemplate">
				<xf:include template="{$typeConfigTemplate}" />
			</xf:if>
			<xf:hiddenval name="forum_type_id">{$forumTypeId}</xf:hiddenval>

			<hr class="formRowSep" />
			<xf:if is="$availableFields is not empty">
				<xf:checkboxrow name="available_fields" value="{$forum.field_cache}" listclass="field listColumns"
					label="{{ phrase('available_fields') }}"
					explain="{{ phrase('asterisk_fields_required_explain') }}">

					<xf:foreach loop="$availableFields" key="$fieldId" value="$field">
						<xf:option value="{$fieldId}" label="{$field.title}" labelclass="{{ $field.required ? 'u-appendAsterisk' : '' }}" />
					</xf:foreach>

					<xf:hint>
						<xf:checkbox standalone="true">
							<xf:option check-all=".field.listColumns">{{ phrase('select_all') }}</xf:option>
						</xf:checkbox>
					</xf:hint>
				</xf:checkboxrow>
			<xf:else />
				<xf:formrow label="{{ phrase('available_fields') }}">
					{{ phrase('none')|parens }}
					<a href="{{ link('custom-thread-fields/add') }}" target="_blank">{{ phrase('add_field') }}</a>
				</xf:formrow>
			</xf:if>

			<hr class="formRowSep" />
			<xf:if is="$prefixesGrouped is not empty">

				<xf:checkboxrow name="available_prefixes" rowtype="explainOffset" listclass="prefix"
					data-xf-init="checkbox-select-disabler"
					data-select=".js-availablePrefixSelect"
					label="{{ phrase('available_prefixes') }}"
					explain="{{ phrase('available_prefixes_forum_explain') }}">

					<xf:foreach loop="$prefixGroups" key="$prefixGroupId" value="$prefixGroup" if="{$prefixesGrouped.{$prefixGroupId}}">

						<xf:optgroup check-all="true" listclass="listColumns"
							label="{{ $prefixGroupId ? $prefixGroup.title : phrase('ungrouped') }}">

							<xf:foreach loop="{$prefixesGrouped.{$prefixGroupId}}" key="$prefixId" value="$prefix">
								<xf:option value="{$prefixId}" selected="{$forum.prefix_cache.{$prefixId}}">
									<xf:label><span class="label {$prefix.css_class}">{$prefix.title}</span></xf:label>
								</xf:option>
							</xf:foreach>
						</xf:optgroup>
					</xf:foreach>

					<xf:hint>
						<xf:checkbox standalone="true">
							<xf:option check-all=".prefix">{{ phrase('select_all') }}</xf:option>
						</xf:checkbox>
					</xf:hint>
				</xf:checkboxrow>

				<xf:selectrow name="default_prefix_id" value="{$forum.default_prefix_id}"
					label="{{ phrase('default_thread_prefix') }}"
					explain="{{ phrase('default_thread_prefix_explain') }}"
					class="js-availablePrefixSelect">

					<xf:option value="-1">{{ phrase('none') }}</xf:option>
					<xf:foreach loop="$prefixGroups" key="$prefixGroupId" value="$prefixGroup"
						if="{{ count($prefixesGrouped.{$prefixGroupId}) > 0 }}">
						<xf:optgroup label="{{ $prefixGroupId > 0 ? $prefixGroup.title : phrase('ungrouped') }}">
							<xf:foreach loop="{$prefixesGrouped.{$prefixGroupId}}" key="$prefixId" value="$prefix">
								<xf:option value="{$prefixId}" disabled="{{ !in_array($prefixId, $forum.prefix_cache) }}">{$prefix.title}</xf:option>
							</xf:foreach>
						</xf:optgroup>
					</xf:foreach>
				</xf:selectrow>

				<xf:checkboxrow name="require_prefix" value="{$forum.require_prefix}">
					<xf:option value="1"
						label="{{ phrase('require_users_to_select_prefix') }}"
						hint="{{ phrase('if_selected_users_required_select_prefix_for_thread') }}" />
				</xf:checkboxrow>

			<xf:else />
				<xf:formrow label="{{ phrase('available_prefixes') }}">
					{{ phrase('none')|parens }} <a href="{{ link('thread-prefixes/add') }}" target="_blank">{{ phrase('add_prefix') }}</a>
				</xf:formrow>

				<xf:hiddenval name="default_thread_prefix" value="0" />
				<xf:hiddenval name="require_prefix" value="0" />
			</xf:if>

		</div>

		<h3 class="block-formSectionHeader">
			<span class="collapseTrigger collapseTrigger--block" data-xf-click="toggle" data-target="< :up:next">
				<span class="block-formSectionHeader-aligner">{{ phrase('advanced_options') }}</span>
			</span>
		</h3>
		<div class="block-body block-body--collapsible">
			<xf:checkboxrow rowid="advancedToggles">
				<xf:option name="allow_posting" selected="$forum.allow_posting"
					label="{{ phrase('allow_new_messages_to_be_posted_in_this_forum') }}"
					hint="{{ phrase('if_disabled_users_not_able_post_messages_in_forum') }}" />

				<xf:option name="moderate_threads" selected="$forum.moderate_threads"
					label="{{ phrase('moderate_new_threads_posted_in_this_forum') }}"
					hint="{{ phrase('if_enabled_moderator_manually_approve_threads_posted_in_forum') }}" />

				<xf:option name="moderate_replies" selected="$forum.moderate_replies"
					label="{{ phrase('moderate_replies_posted_in_this_forum') }}"
					hint="{{ phrase('if_enabled_moderator_manually_approve_replies_posted_in_forum') }}" />

				<xf:option name="count_messages" selected="$forum.count_messages"
					label="{{ phrase('count_messages_in_forum_toward_user_total') }}"
					hint="{{ phrase('if_disabled_messages_posted_will_not_contribute_to_user_message_total') }}" />

				<xf:option name="find_new" selected="$forum.find_new"
					label="{{ phrase('include_forum_in_find_new_threads') }}"
					hint="{{ phrase('if_disabled_messages_will_never_appear_in_find_new_threads') }}" />
			</xf:checkboxrow>

			<xf:radiorow name="allow_index" value="{$forum.allow_index}"
				label="{{ phrase('allow_search_engine_indexing') }}"
				explain="{{ phrase('you_can_choose_whether_or_not_to_allow_external_search_engines_to_index') }}">

				<xf:option value="allow">{{ phrase('index_all_threads') }}</xf:option>
				<xf:option value="deny">{{ phrase('do_not_index_any_threads') }}</xf:option>
				<xf:option value="criteria"
					data-xf-init="disabler" data-container=".js-indexCriteria" data-hide="true">

					{{ phrase('index_threads_based_on_criteria') }}
				</xf:option>
			</xf:radiorow>

			<div class="js-indexCriteria">
				<xf:checkboxrow label="{{ phrase('search_engine_index_criteria') }}">
					<xf:option name="index_criteria[max_days_post][enabled]" selected="{$forum.index_criteria.max_days_post}"
						label="{{ phrase('thread_was_posted_no_more_than_x_days_ago:') }}">

						<xf:numberbox name="index_criteria[max_days_post][value]" value="{{ $forum.index_criteria.max_days_post ?: 1 }}"
							min="1" />
					</xf:option>

					<xf:option name="index_criteria[max_days_last_post][enabled]" selected="{$forum.index_criteria.max_days_last_post}"
						label="{{ phrase('thread_was_replied_to_no_more_than_x_days_ago:') }}">

						<xf:numberbox name="index_criteria[max_days_last_post][value]" value="{{ $forum.index_criteria.max_days_last_post ?: 1 }}"
							min="1" />
					</xf:option>

					<xf:option name="index_criteria[min_replies][enabled]" selected="{$forum.index_criteria.min_replies}"
						label="{{ phrase('thread_has_at_least_x_replies:') }}">

						<xf:numberbox name="index_criteria[min_replies][value]" value="{{ $forum.index_criteria.min_replies ?: 1 }}"
							min="1" />
					</xf:option>

					<xf:option name="index_criteria[min_reaction_score][enabled]" selected="{{ $forum.index_criteria.min_reaction_score !== null }}"
						label="{{ phrase('thread_has_at_least_x_reaction_score:') }}">

						<xf:numberbox name="index_criteria[min_reaction_score][value]" value="{{ $forum.index_criteria.min_reaction_score ?: 0 }}" />
					</xf:option>
				</xf:checkboxrow>
			</div>

			<xf:numberboxrow name="min_tags" value="{$forum.min_tags}" min="0" max="100"
				label="{{ phrase('minimum_required_tags') }}"
				explain="{{ phrase('forum_min_tags_explain') }}" />

			<xf:radiorow name="allowed_watch_notifications" value="{$forum.allowed_watch_notifications}"
				label="{{ phrase('forum_watch_notification_limit') }}"
				explain="{{ phrase('forum_watch_notification_limit_desc') }}">

				<xf:option value="all" label="{{ phrase('new_messages') }}" />
				<xf:option value="thread" label="{{ phrase('new_threads') }}" />
				<xf:option value="none" label="{{ phrase('none') }}" />
			</xf:radiorow>

			<xf:formrow rowtype="input"
				label="{{ phrase('default_sort_order') }}">

				<div class="inputPair">
					<xf:select name="default_sort_order" value="{$forum.default_sort_order}" class="input--inline">
						<xf:foreach loop="$sortOptions" key="$sortKey" value="$null">
							<xf:option value="{$sortKey}">{{ phrase_dynamic('forum_sort.' . $sortKey) }}</xf:option>
						</xf:foreach>
					</xf:select>
					<xf:select name="default_sort_direction" value="{$forum.default_sort_direction}"
						class="input--inline">
						<xf:option value="desc" label="{{ phrase('descending') }}" />
						<xf:option value="asc" label="{{ phrase('ascending') }}" />
					</xf:select>
				</div>
			</xf:formrow>

			<xf:selectrow name="list_date_limit_days" value="{$forum.list_date_limit_days}"
				label="{{ phrase('thread_list_date_limit') }}"
				explain="{{ phrase('thread_list_date_limit_used_on_busy_forums_to_improve_performance') }}">

				<xf:option value="0">{{ phrase('none') }}</xf:option>
				<xf:option value="7">{{ phrase('x_days', {'days': '7'}) }}</xf:option>
				<xf:option value="14">{{ phrase('x_days', {'days': '14'}) }}</xf:option>
				<xf:option value="30">{{ phrase('x_days', {'days': '30'}) }}</xf:option>
				<xf:option value="60">{{ phrase('x_months', {'months': '2'}) }}</xf:option>
				<xf:option value="90">{{ phrase('x_months', {'months': '3'}) }}</xf:option>
				<xf:option value="182">{{ phrase('x_months', {'months': '6'}) }}</xf:option>
				<xf:option value="365">{{ phrase('1_year') }}</xf:option>
			</xf:selectrow>

			<xf:macro template="node_edit_macros" name="style" arg-node="{$node}" arg-styleTree="{$styleTree}" />

			<xf:if is="$availablePrompts is not empty">
				<hr class="formRowSep" />

				<xf:checkboxrow name="available_prompts" rowtype="explainOffset" listclass="prompt"
					label="{{ phrase('available_prompts') }}"
					explain="{{ phrase('available_thread_prompts_explain',
					{
						'link': link(
							'phrases/edit-by-name', {},
							{'title': 'thread_prompt.default'}
						)
					}) }}">

					<xf:foreach loop="$promptGroups" key="$promptGroupId" value="$promptGroup" if="{$promptsGrouped.{$promptGroupId}}">

						<xf:optgroup check-all="true" listclass="_listColumns"
							label="{{ $promptGroupId ? $promptGroup.title : phrase('ungrouped') }}">

							<xf:foreach loop="{$promptsGrouped.{$promptGroupId}}" key="$promptId" value="$prompt">
								<xf:option value="{$promptId}" selected="{$forum.prompt_cache.{$promptId}}">
									<xf:label>{$prompt.title}</xf:label>
								</xf:option>
							</xf:foreach>
						</xf:optgroup>
					</xf:foreach>

					<xf:hint>
						<xf:checkbox standalone="true">
							<xf:option check-all=".prompt">{{ phrase('select_all') }}</xf:option>
						</xf:checkbox>
					</xf:hint>
				</xf:checkboxrow>

			</xf:if>
		</div>

		<xf:submitrow icon="save" sticky="true" />
	</div>
</xf:form>