<%--
/**
 * 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="/repository_entry_browser/init.jsp" %>

<div class="search-info">

	<%
	long folderId = ParamUtil.getLong(request, "folderId");
	String keywords = ParamUtil.getString(request, "keywords");

	boolean searchEverywhere = true;

	long searchFolderId = ParamUtil.getLong(request, "searchFolderId");

	boolean showRerunSearchButton = true;

	if (folderId > DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
		searchEverywhere = false;
	}
	else {
		folderId = searchFolderId;
	}

	if ((folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) && (searchFolderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {
		showRerunSearchButton = false;
	}
	%>

	<c:if test="<%= showRerunSearchButton %>">

		<%
		PortletURL portletURL = (PortletURL)request.getAttribute("liferay-item-selector:repository-entry-browser:portletURL");

		PortletURL searchEverywhereURL = PortletURLUtil.clone(portletURL, liferayPortletResponse);

		searchEverywhereURL.setParameter("folderId", String.valueOf(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID));
		searchEverywhereURL.setParameter("searchFolderId", String.valueOf(folderId));
		searchEverywhereURL.setParameter("keywords", keywords);

		PortletURL searchFolderURL = PortletURLUtil.clone(searchEverywhereURL, liferayPortletResponse);

		searchFolderURL.setParameter("folderId", String.valueOf(folderId));
		%>

		<liferay-util:whitespace-remover>
			<liferay-ui:message key="search" />

			<clay:link
				cssClass='<%= searchEverywhere ? "active" : "" %>'
				displayType="secondary"
				href="<%= searchEverywhereURL.toString() %>"
				label="everywhere"
				small="<%= true %>"
				type="button"
			/>

			<%
			Folder folder = DLAppServiceUtil.getFolder(folderId);
			%>

			<clay:link
				cssClass='<%= !searchEverywhere ? "active" : "" %>'
				displayType="secondary"
				href="<%= searchFolderURL.toString() %>"
				icon="folder"
				label="<%= folder.getName() %>"
				type="button"
			/>
		</liferay-util:whitespace-remover>
	</c:if>
</div>