<%--
/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * Subscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */
--%>

<liferay-ui:search-container
	headerNames="thread,started-by,posts,views,last-post"
	iteratorURL="<%= portletURL %>"
>

	<%
	String emptyResultsMessage = null;

	if (mvcRenderCommandName.equals("/message_boards/view_my_subscriptions")) {
		emptyResultsMessage = "you-are-not-subscribed-to-any-threads";
	}
	else {
		emptyResultsMessage = "there-are-no-threads-in-this-category";
	}

	searchContainer.setEmptyResultsMessage(emptyResultsMessage);
	%>

	<liferay-ui:search-container-results>

		<%
		if (mvcRenderCommandName.equals("/message_boards/view_my_subscriptions")) {
			total = MBThreadServiceUtil.getGroupThreadsCount(scopeGroupId, groupThreadsUserId, WorkflowConstants.STATUS_APPROVED, true);

			searchContainer.setTotal(total);

			results = MBThreadServiceUtil.getGroupThreads(scopeGroupId, groupThreadsUserId, WorkflowConstants.STATUS_APPROVED, true, searchContainer.getStart(), searchContainer.getEnd());
		}
		else if (useAssetEntryQuery) {
			AssetEntryQuery assetEntryQuery = new AssetEntryQuery(MBMessage.class.getName(), searchContainer);

			assetEntryQuery.setEnablePermissions(true);
			assetEntryQuery.setExcludeZeroViewCount(false);

			total = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);

			searchContainer.setTotal(total);

			assetEntryQuery.setEnd(searchContainer.getEnd());
			assetEntryQuery.setStart(searchContainer.getStart());

			results = AssetEntryServiceUtil.getEntries(assetEntryQuery);
		}

		searchContainer.setResults(results);
		%>

	</liferay-ui:search-container-results>

	<liferay-ui:search-container-row
		className="com.liferay.portal.kernel.model.BaseModel"
		keyProperty="primaryKeyObj"
		modelVar="result"
	>
		<%@ include file="/message_boards/thread_cast_result.jspf" %>

		<%
		MBMessage message = MBMessageLocalServiceUtil.fetchMBMessage(thread.getRootMessageId());

		if (message == null) {
			_log.error("Thread requires missing root message id " + thread.getRootMessageId());

			row.setSkip(true);
		}

		if (message != null) {
			message = message.toEscapedModel();

			row.setBold(!MBThreadFlagLocalServiceUtil.hasThreadFlag(themeDisplay.getUserId(), thread));
			row.setRestricted(!MBMessagePermission.contains(permissionChecker, message, ActionKeys.VIEW));
		}
		%>

		<liferay-portlet:renderURL varImpl="rowURL">
			<portlet:param name="mvcRenderCommandName" value="/message_boards/view_message" />
			<portlet:param name="messageId" value="<%= (message != null) ? String.valueOf(message.getMessageId()) : String.valueOf(MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID) %>" />
		</liferay-portlet:renderURL>

		<%@ include file="/message_boards/user_thread_columns.jspf" %>
	</liferay-ui:search-container-row>

	<liferay-ui:search-iterator
		markupView="lexicon"
	/>
</liferay-ui:search-container>