<%--
/**
 * 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.
 *
 *
 *
 */
--%>

<%@ include file="/init.jsp" %>

<%
long layoutSetBranchId = ParamUtil.getLong(request, "layoutSetBranchId");

List<LayoutRevision> layoutRevisions = LayoutRevisionLocalServiceUtil.getChildLayoutRevisions(layoutSetBranchId, LayoutRevisionConstants.DEFAULT_PARENT_LAYOUT_REVISION_ID, plid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, new LayoutRevisionCreateDateComparator(true));

long layoutRevisionId = StagingUtil.getRecentLayoutRevisionId(request, layoutSetBranchId, plid);

LayoutRevision currentLayoutRevision = null;

if (layoutRevisionId <= 0) {
	LayoutBranch layoutBranch = LayoutBranchLocalServiceUtil.getMasterLayoutBranch(layoutSetBranchId, plid);

	currentLayoutRevision = LayoutRevisionLocalServiceUtil.getLayoutRevision(layoutSetBranchId, layoutBranch.getLayoutBranchId(), plid);

	layoutRevisionId = currentLayoutRevision.getLayoutRevisionId();
}
else {
	currentLayoutRevision = LayoutRevisionLocalServiceUtil.getLayoutRevision(layoutRevisionId);
}

request.setAttribute("view_layout_branches.jsp-currenttLayoutBranchId", String.valueOf(currentLayoutRevision.getLayoutBranchId()));
%>

<liferay-util:include page="/navigation.jsp" servletContext="<%= application %>">
	<liferay-util:param name="navigationName" value="page-variations" />
</liferay-util:include>

<clay:container-fluid>
	<liferay-ui:success key="pageVariationAdded" message="page-variation-was-added" />
	<liferay-ui:success key="pageVariationDeleted" message="page-variation-was-deleted" />
	<liferay-ui:success key="pageVariationUpdated" message="page-variation-was-updated" />

	<div class="lfr-alert-container"></div>

	<c:if test="<%= GroupPermissionUtil.contains(permissionChecker, stagingGroup, ActionKeys.ADD_LAYOUT_BRANCH) %>">
		<liferay-portlet:renderURL var="addLayoutBranchURL">
			<portlet:param name="mvcRenderCommandName" value="editLayoutBranch" />
			<portlet:param name="redirect" value="<%= currentURL %>" />
			<portlet:param name="layoutRevisionId" value="<%= String.valueOf(layoutRevisionId) %>" />
		</liferay-portlet:renderURL>

		<aui:button-row>
			<aui:button href="<%= addLayoutBranchURL %>" name="addRootLayoutBranch" value="add-page-variation" />
		</aui:button-row>
	</c:if>

	<div class="branch-results">
		<liferay-ui:search-container
			total="<%= layoutRevisions.size() %>"
		>
			<liferay-ui:search-container-results
				results="<%= layoutRevisions %>"
			/>

			<liferay-ui:search-container-row
				className="com.liferay.portal.kernel.model.LayoutRevision"
				escapedModel="<%= true %>"
				keyProperty="layoutRevisionId"
				modelVar="layoutRevision"
			>

				<%
				LayoutBranch layoutBranch = layoutRevision.getLayoutBranch();
				%>

				<liferay-ui:search-container-column-text
					name="name"
				>
					<c:if test="<%= layoutRevision.getLayoutBranchId() == currentLayoutRevision.getLayoutBranchId() %>">
						<strong>
					</c:if>

					<liferay-ui:message key="<%= HtmlUtil.escape(layoutBranchDisplayContext.getLayoutBranchDisplayName(layoutBranch)) %>" localizeKey="<%= false %>" />

					<c:if test="<%= layoutBranch.isMaster() %>">
						<i class="icon-asterisk"></i>
					</c:if>

					<c:if test="<%= layoutRevision.getLayoutBranchId() == currentLayoutRevision.getLayoutBranchId() %>">
						</strong>
					</c:if>
				</liferay-ui:search-container-column-text>

				<liferay-ui:search-container-column-text
					name="description"
					value="<%= HtmlUtil.escape(layoutBranch.getDescription()) %>"
				/>

				<liferay-ui:search-container-column-jsp
					align="right"
					cssClass="entry-action"
					path="/layout_branch_action.jsp"
				/>
			</liferay-ui:search-container-row>

			<liferay-ui:search-iterator
				markupView="lexicon"
				paginate="<%= false %>"
				searchContainer="<%= searchContainer %>"
			/>
		</liferay-ui:search-container>
	</div>
</clay:container-fluid>

<aui:script position="inline" use="liferay-staging-branch">
	Liferay.StagingBar.init({
		namespace: '<portlet:namespace />',
		portletId: '<%= portletDisplay.getId() %>',
	});
</aui:script>