<%
/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */
%>

<%
layoutView = layoutLister.getLayoutView(scopeGroupId, privateLayout, "root", locale);

layoutList = layoutView.getList();

if (layoutList.size() > 1) {
%>

	<optgroup label="<%= LanguageUtil.get(pageContext, privateLayout ? "private-pages" : "public-pages") %>">

	<%
	for (int i = 0; i < layoutList.size(); i++) {

		// id | parentId | ls | obj id | name | img | depth

		String layoutDesc = (String)layoutList.get(i);

		String[] nodeValues = StringUtil.split(layoutDesc, "|");

		long objId = GetterUtil.getLong(nodeValues[3]);
		String name = nodeValues[4];

		int depth2 = 0;

		if (i != 0) {
			depth2 = GetterUtil.getInteger(nodeValues[6]);
		}

		for (int j = 0; j < depth2; j++) {
			name = "-&nbsp;" + name;
		}

		Layout linkableLayout = null;

		try {
			linkableLayout = LayoutLocalServiceUtil.getLayout(objId);
		}
		catch (Exception e) {
		}

		if (linkableLayout != null) {
			if (elContent.indexOf(StringPool.AT) == -1) {
				elContent += "@public";
			}

			String suffix = null;

			if (privateLayout) {
				if (linkableLayout.getGroup().isUser()) {
					suffix = "private-user";
				}
				else {
					suffix = "private-group";
				}
			}
			else {
				suffix = "public";
			}

			String layoutLink = linkableLayout.getLayoutId() + StringPool.AT + suffix;
	%>

			<option <%= elContent.equals(layoutLink) ? "selected" : "" %> value="<%= layoutLink %>"><%= name %></option>

	<%
		}
	}
	%>

	</optgroup>

<%
}
%>