<core:FragmentDefinition
	xmlns:uxap="sap.uxap"
	xmlns:core="sap.ui.core"
	xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1"
	template:require="{
		MODEL: 'sap/ui/model/odata/v4/AnnotationHelper',
		COMMON: 'sap/fe/macros/CommonHelper'
	}">
	<!--
	For HeaderFacets, we add a section to the OP which is only visible in edit mode.
	It has one section with one subsection for all of the header facets, block for each facet.
	-->
	<template:if test="{= ${metaPath>/currentPath}.set('@com.sap.vocabularies.UI.v1.HeaderFacets') }" />
	<template:if test="{entityType>@com.sap.vocabularies.UI.v1.HeaderFacets}">
		<uxap:ObjectPageSection title="{sap.fe.i18n>OBJECT_PAGE_HEADER_SECTION}" visible="{= ${ui>/editable} === 'Editable' }" titleUppercase="false">
			<uxap:subSections>
				<uxap:ObjectPageSubSection>
					<core:Fragment fragmentName="sap.fe.templates.ObjectPage.view.fragments.EditableHeaderFacet" type="XML"/>
				</uxap:ObjectPageSubSection>
			</uxap:subSections>
		</uxap:ObjectPageSection>
	</template:if>
	<template:if test="{= ${metaPath>/currentPath}.set('../') }" />
	<template:if test="{= ${metaPath>/currentPath}.set('/') }" />
	<template:if test="{= ${metaPath>/currentPath}.set('@com.sap.vocabularies.UI.v1.Facets') }" />
	<template:repeat list="{entityType>@com.sap.vocabularies.UI.v1.Facets}" var="firstLevelFacet">
	<template:if test="{= !(${firstLevelFacet>./@com.sap.vocabularies.UI.v1.Hidden} === true)}">
		<uxap:ObjectPageSection
			id="{= COMMON.getStableId(['fe', 'ops', { Facet: ${firstLevelFacet>} }]) }"
			title="{firstLevelFacet>@@MODEL.label}"
			titleUppercase="false"
			visible="{= ${firstLevelFacet>./@com.sap.vocabularies.UI.v1.Hidden/$Path} ? ('{= !${' + ${firstLevelFacet>./@com.sap.vocabularies.UI.v1.Hidden/$Path} + '} }') : true }">
			<uxap:subSections>
				<template:if test="{path: 'firstLevelFacet>', formatter: 'sap.fe.templates.ObjectPage.AnnotationHelper.isDeepFacetHierarchy'}">
					<template:then>
						<template:repeat list="{firstLevelFacet>Facets}" var="facet">
							<!--This refers to the secondLevelFacet-->
							<template:if test="{= !(${facet>./@com.sap.vocabularies.UI.v1.Hidden} === true)}">
							<uxap:ObjectPageSubSection
								id="{= COMMON.getStableId(['fe', 'opss', { Facet: ${facet>} }]) }"
								title="{facet>@@MODEL.label}"
								visible="{= ${facet>./@com.sap.vocabularies.UI.v1.Hidden/$Path} ? ('{= !${' + ${facet>./@com.sap.vocabularies.UI.v1.Hidden/$Path} + '} }') : true }">
								<uxap:customData>
									<core:CustomData key="strategyForVisibilityChange" value="lazyLoading" />
								</uxap:customData>
								<core:Fragment fragmentName="sap.fe.templates.ObjectPage.view.fragments.ObjectPageBlocksAndMoreBlocks" type="XML"/>
							</uxap:ObjectPageSubSection>
							</template:if>
						</template:repeat>
					</template:then>
					<template:else>
						<uxap:ObjectPageSubSection
							id="{= COMMON.getStableId(['fe', 'opss', { Facet: ${firstLevelFacet>} }]) }"
							title="{firstLevelFacet>Label@@MODEL.value}"
							visible="{= ${firstLevelFacet>./@com.sap.vocabularies.UI.v1.Hidden/$Path} ? ('{= !${' + ${firstLevelFacet>./@com.sap.vocabularies.UI.v1.Hidden/$Path} + '} }') : true }">
							<uxap:customData>
								<core:CustomData key="strategyForVisibilityChange" value="lazyLoading"/>
							</uxap:customData>
							<template:with path="firstLevelFacet>" var="facet">
								<core:Fragment fragmentName="sap.fe.templates.ObjectPage.view.fragments.ObjectPageBlocksAndMoreBlocks" type="XML"/>
							</template:with>
						</uxap:ObjectPageSubSection>
					</template:else>
				</template:if>
			</uxap:subSections>
		</uxap:ObjectPageSection>
		</template:if>
	</template:repeat>
</core:FragmentDefinition>