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

<%
ResultRow row = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);

Layout curLayout = (Layout)row.getObject();
%>

<liferay-ui:icon-menu
	direction="left-side"
	icon="<%= StringPool.BLANK %>"
	markupView="lexicon"
	message="<%= StringPool.BLANK %>"
	showWhenSingleIcon="<%= true %>"
>
	<c:if test="<%= layoutsAdminDisplayContext.isShowViewLayoutAction(curLayout) %>">
		<liferay-ui:icon
			message="view"
			url="<%= layoutsAdminDisplayContext.getViewLayoutURL(curLayout) %>"
		/>
	</c:if>

	<%
	String editLayoutURL = layoutsAdminDisplayContext.getEditLayoutURL(curLayout);
	%>

	<c:if test="<%= Validator.isNotNull(editLayoutURL) %>">
		<liferay-ui:icon
			message='<%= layoutsAdminDisplayContext.isConversionDraft(layout) ? "edit-conversion-draft" : "edit" %>'
			url="<%= editLayoutURL %>"
		/>
	</c:if>

	<c:if test="<%= layoutsAdminDisplayContext.isShowConfigureAction(curLayout) %>">
		<liferay-ui:icon
			message="configure"
			url="<%= layoutsAdminDisplayContext.getConfigureLayoutURL(curLayout) %>"
		/>
	</c:if>

	<c:if test="<%= layoutsAdminDisplayContext.isShowAddChildPageAction(curLayout) %>">
		<liferay-ui:icon
			message="add-child-page"
			url="<%= layoutsAdminDisplayContext.getSelectLayoutPageTemplateEntryURL(layoutsAdminDisplayContext.getFirstLayoutPageTemplateCollectionId(), curLayout.getPlid(), curLayout.isPrivateLayout()) %>"
		/>
	</c:if>

	<c:if test="<%= layoutsAdminDisplayContext.isShowCopyLayoutAction(curLayout) %>">
		<liferay-ui:icon
			data='<%=
				HashMapBuilder.<String, Object>put(
					"url", layoutsAdminDisplayContext.getCopyLayoutRenderURL(curLayout)
				).build()
			%>'
			linkCssClass='<%= liferayPortletResponse.getNamespace() + "copy-layout-action-option" %>'
			message="copy-page"
			url="javascript:;"
		/>
	</c:if>

	<c:if test="<%= layoutsAdminDisplayContext.isShowPermissionsAction(curLayout) %>">
		<liferay-ui:icon
			message="permissions"
			method="get"
			url="<%= layoutsAdminDisplayContext.getPermissionsURL(curLayout) %>"
			useDialog="<%= true %>"
		/>
	</c:if>

	<c:if test="<%= layoutsAdminDisplayContext.isShowOrphanPortletsAction(curLayout) %>">
		<liferay-ui:icon
			message="orphan-widgets"
			url="<%= layoutsAdminDisplayContext.getOrphanPortletsPortletURL(curLayout) %>"
		/>
	</c:if>

	<c:if test="<%= layoutsAdminDisplayContext.isShowConvertLayoutAction(curLayout) %>">
		<liferay-ui:icon
			message="convert-to-content-page..."
			url="<%= layoutsAdminDisplayContext.getConvertLayoutURL(curLayout) %>"
		/>
	</c:if>

	<c:if test="<%= layoutsAdminDisplayContext.isShowDeleteAction(curLayout) %>">

		<%
		String messageKey = "are-you-sure-you-want-to-delete-this-page";

		if (curLayout.hasChildren() && _hasScopeGroup(curLayout)) {
			messageKey = "this-page-is-being-used-as-a-scope-for-content-and-also-has-child-pages";
		}
		else if (curLayout.hasChildren()) {
			messageKey = "this-page-has-child-pages-that-will-also-be-removed";
		}
		else if (_hasScopeGroup(curLayout)) {
			messageKey = "this-page-is-being-used-as-a-scope-for-content";
		}
		%>

		<liferay-ui:icon-delete
			confirmation="<%= messageKey %>"
			url="<%= layoutsAdminDisplayContext.getDeleteLayoutURL(curLayout) %>"
		/>
	</c:if>

	<c:if test="<%= layoutsAdminDisplayContext.isShowDraftActions(curLayout) %>">
		<liferay-ui:icon
			message="preview-draft"
			url="<%= layoutsAdminDisplayContext.getPreviewDraftURL(curLayout) %>"
		/>

		<liferay-ui:icon
			message="discard-draft"
			url="<%= layoutsAdminDisplayContext.getDiscardDraftURL(curLayout) %>"
		/>
	</c:if>

	<c:if test="<%= layoutsAdminDisplayContext.isShowViewCollectionItemsAction(curLayout) %>">
		<liferay-ui:icon
			data='<%=
				HashMapBuilder.<String, Object>put(
					"url", layoutsAdminDisplayContext.getViewCollectionItemsURL(curLayout)
				).build()
			%>'
			linkCssClass='<%= liferayPortletResponse.getNamespace() + "view-collection-items-action-option" %>'
			message="view-collection-items"
			url="javascript:;"
		/>
	</c:if>
</liferay-ui:icon-menu>

<%!
private boolean _hasScopeGroup(Layout layout) throws Exception {
	if (layout.hasScopeGroup()) {
		return true;
	}

	Layout draftLayout = layout.fetchDraftLayout();

	if (draftLayout == null) {
		return false;
	}

	return draftLayout.hasScopeGroup();
}
%>