<?xml version="1.0" encoding="UTF-8"?>
<!--
	* Licensed to the Apache Software Foundation (ASF) under one or more
	* contributor license agreements.  See the NOTICE file distributed with
	* this work for additional information regarding copyright ownership.
	* The ASF licenses this file to You under the Apache License, Version 2.0
	* (the "License"); you may not use this file except in compliance with
	* the License.  You may obtain a copy of the License at
	*
	*      http://www.apache.org/licenses/LICENSE-2.0
	*
	* Unless required by applicable law or agreed to in writing, software
	* distributed under the License is distributed on an "AS IS" BASIS,
	* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	* See the License for the specific language governing permissions and
	* limitations under the License.
-->

<ui:composition
    xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:tc="http://myfaces.apache.org/tobago/component"
	xmlns:tfs="http://myfaces.apache.org/tobago/facelet-sandbox">
	
	<c:if test="${empty showMasterNavigation}">
		<c:set var="showMasterNavigation" value="true" />
	</c:if>
	<c:set var="replaceMasterNavigation" value="true" />
	<c:if test="${empty navigationMasterSource}" >
		<c:set var="replaceMasterNavigation" value="false" />
	</c:if>
	
	<c:if test="${empty showDetailNavigation}">
		<c:set var="showMasterNavigation" value="true" />
	</c:if>
	<c:set var="replaceDetailNavigation" value="true" />
	<c:if test="${empty navigationDetailSource}" >
		<c:set var="replaceDetailNavigation" value="false" />
	</c:if>
	
	<!-- show master or detail content view -->
	<c:choose>
		<c:when test="${!controller.showDetail}">
			<!-- master view -->
			<tc:panel>
				<f:facet name="layout">
					<tc:gridLayout rows="*;auto" />
				</f:facet>
				
				<!-- detail content area -->
				<ui:include src="${contentMasterSource}" />
				<!-- detail navigation area -->
				<c:choose>
					<c:when test="${showMasterNavigation}">
						<c:choose>
							<c:when test="${replaceMasterNavigation}">
								<ui:include src="${navigationMasterSource}" />
							</c:when>
							<c:otherwise>
								<tfs:crud-master-navigation controller="${controller}" />
							</c:otherwise>
						</c:choose>
					</c:when>
					<c:otherwise>
						<tc:cell />
					</c:otherwise>
				</c:choose>
			</tc:panel>
		</c:when>
		<c:otherwise>
			<!--detail view -->
			<tc:panel>
				<f:facet name="layout">
					<tc:gridLayout rows="*;auto" />
				</f:facet>
				
				<!-- detail content area -->
				<ui:include src="${contentDetailSource}" />
				<!-- detail navigation area -->
				<c:choose>
					<c:when test="${showDetailNavigation}">
						<c:choose>
							<c:when test="${replaceDetailNavigation}">
								<ui:include src="${navigationDetailSource}" />
							</c:when>
							<c:otherwise>
								<tfs:crud-detail-navigation controller="${controller}" />
							</c:otherwise>
						</c:choose>
					</c:when>
					<c:otherwise>
						<tc:cell />
					</c:otherwise>
				</c:choose>
			</tc:panel>
		</c:otherwise>
	</c:choose>
	
</ui:composition>
