<%--
/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */
--%>

<aui:fieldset>
	<aui:input name="preferences--enableRelatedAssets--" type="checkbox" value="<%= enableRelatedAssets %>" />

	<c:if test="<%= PropsValues.WIKI_PAGE_RATINGS_ENABLED || PropsValues.WIKI_PAGE_COMMENTS_ENABLED %>">
		<c:if test="<%= PropsValues.WIKI_PAGE_RATINGS_ENABLED %>">
			<aui:input name="preferences--enablePageRatings--" type="checkbox" value="<%= enablePageRatings %>" />
		</c:if>

		<c:if test="<%= PropsValues.WIKI_PAGE_COMMENTS_ENABLED %>">
			<aui:input name="preferences--enableComments--" type="checkbox" value="<%= enableComments %>" />

			<aui:input name="preferences--enableCommentRatings--" type="checkbox" value="<%= enableCommentRatings %>" />
		</c:if>
	</c:if>
</aui:fieldset>

<aui:fieldset>
	<div class="display-template">

		<%
		TemplateHandler templateHandler = TemplateHandlerRegistryUtil.getTemplateHandler(WikiPage.class.getName());
		%>

		<liferay-ui:ddm-template-selector
			classNameId="<%= PortalUtil.getClassNameId(templateHandler.getClassName()) %>"
			displayStyle="<%= displayStyle %>"
			displayStyleGroupId="<%= displayStyleGroupId %>"
			refreshURL="<%= configurationRenderURL %>"
			showEmptyOption="<%= true %>"
		/>
	</div>
</aui:fieldset>

<aui:fieldset label="visible-wikis">
	<aui:input name="preferences--visibleNodes--" type="hidden" />
	<aui:input name="preferences--hiddenNodes--" type="hidden" />

	<%
	Set<String> currentVisibleNodes = new HashSet<String>(allNodeNames);

	// Left list

	List<KeyValuePair> leftList = new ArrayList<KeyValuePair>();

	for (String folderColumn : visibleNodes) {
		if (currentVisibleNodes.contains(folderColumn)) {
			leftList.add(new KeyValuePair(folderColumn, HtmlUtil.escape(LanguageUtil.get(pageContext, folderColumn))));
		}
	}

	Arrays.sort(visibleNodes);
	Arrays.sort(hiddenNodes);

	for (String folderColumn : currentVisibleNodes) {
		if ((Arrays.binarySearch(hiddenNodes, folderColumn) < 0) && (Arrays.binarySearch(visibleNodes, folderColumn) < 0)) {
			leftList.add(new KeyValuePair(folderColumn, HtmlUtil.escape(LanguageUtil.get(pageContext, folderColumn))));
		}
	}

	// Right list

	List<KeyValuePair> rightList = new ArrayList<KeyValuePair>();

	for (String folderColumn : hiddenNodes) {
		if (currentVisibleNodes.contains(folderColumn)) {
			if (Arrays.binarySearch(visibleNodes, folderColumn) < 0) {
				rightList.add(new KeyValuePair(folderColumn, HtmlUtil.escape(LanguageUtil.get(pageContext, folderColumn))));
			}
		}
	}

	rightList = ListUtil.sort(rightList, new KeyValuePairComparator(false, true));
	%>

	<liferay-ui:input-move-boxes
		leftBoxName="currentVisibleNodes"
		leftList="<%= leftList %>"
		leftReorder="true"
		leftTitle="visible"
		rightBoxName="availableVisibleNodes"
		rightList="<%= rightList %>"
		rightTitle="hidden"
	/>
</aui:fieldset>