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

<%
int groupLevel = GetterUtil.getInteger(request.getAttribute("view.jsp-groupLevel"));

long parentGroupId = GetterUtil.getLong(request.getAttribute("view.jsp-parentGroupId"));

List<Group> childGroups = GroupLocalServiceUtil.getGroups(themeDisplay.getCompanyId(), parentGroupId, true, QueryUtil.ALL_POS, QueryUtil.ALL_POS);

childGroups = ListUtil.filter(childGroups, group -> group.hasPrivateLayouts() || group.hasPublicLayouts());
%>

<c:if test="<%= !childGroups.isEmpty() %>">
	<ul class="level-<%= groupLevel %> sites">

		<%
		for (Group childGroup : childGroups) {
			String className = StringPool.BLANK;

			if (Objects.equals(sitesDirectoryDisplayContext.getDisplayStyle(), "list-hierarchy")) {
				className += "open ";
			}

			if (scopeGroupId == childGroup.getGroupId()) {
				className += "selected";
			}
		%>

			<li class="<%= className %>">
				<c:choose>
					<c:when test="<%= childGroup.getGroupId() != themeDisplay.getScopeGroupId() %>">
						<a class="<%= className %>" href="<%= HtmlUtil.escapeHREF(childGroup.getDisplayURL(themeDisplay, !childGroup.hasPublicLayouts())) %>">
							<%= HtmlUtil.escape(childGroup.getDescriptiveName(themeDisplay.getLocale())) %>
						</a>
					</c:when>
					<c:otherwise>
						<span class="<%= className %>">
							<%= HtmlUtil.escape(childGroup.getDescriptiveName(themeDisplay.getLocale())) %>
						</span>
					</c:otherwise>
				</c:choose>

				<c:if test='<%= Objects.equals(sitesDirectoryDisplayContext.getDisplayStyle(), "list-hierarchy") %>'>

					<%
					request.setAttribute("view.jsp-groupLevel", ++groupLevel);
					request.setAttribute("view.jsp-parentGroupId", childGroup.getGroupId());
					%>

					<liferay-util:include page="/view_child_groups.jsp" servletContext="<%= application %>" />
				</c:if>
			</li>

		<%
		}
		%>

	</ul>
</c:if>