<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns="sap.m" xmlns:build="sap.build"
	xmlns:customData="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1" xmlns:navpopover="sap.ui.comp.navpopover"
	xmlns:smartField="sap.ui.comp.smartfield" xmlns:smc="sap.ui.comp.smartmicrochart"
	xmlns:f="sap.f"
	xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1">

	<!-- Handling UI.DataField for Semantically Connected Fields -->
	<template:if test="{= ${lineItems>Target/AnnotationPath}.indexOf('com.sap.vocabularies.UI.v1.FieldGroup') >= 0}">
		<template:then>
			<template:with path="dataField>Value" helper="sap.ui.model.odata.AnnotationHelper.resolvePath" var="dataFieldValue">
				<template:if
					test="{= ${dataField>RecordType} === 'com.sap.vocabularies.UI.v1.DataField' &amp;&amp; ${path: 'parameter>/settings/routeConfig/', formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.isListReportTemplate'} &amp;&amp; !${path: 'dataFieldValue>', formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.isImageUrl'}}">
					<template:then>
						<smartField:SmartField value="{path: 'dataField>Value', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" editable="false" contextEditable="false" fetchValueListReadOnly="false"
												ariaLabelledBy="{columnId>id}">
							<smartField:configuration>
								<smartField:Configuration displayBehaviour="{parts: [{path: 'dataField>'}, {path: 'entitySet>'}, {path: 'dataFieldTarget>Data'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getTextArrangementForSCFields'}"/>
							</smartField:configuration>
							<template:if test="{= ${dataField>Criticality}}">
								<smartField:controlProposal>
									<smartField:ControlProposal>
										<smartField:objectStatus>
											<smartField:ObjectStatus criticality="{path: 'dataField>Criticality', formatter: 'sap.ui.model.odata.AnnotationHelper.simplePath'}"
																	criticalityRepresentationType="{= (${dataField>CriticalityRepresentation/EnumMember} === 'com.sap.vocabularies.UI.v1.CriticalityRepresentationType/WithoutIcon') ? 'WithoutIcon' : 'WithIcon'}"
																	ariaLabelledBy="{columnId>id}"/>
										</smartField:objectStatus>
									</smartField:ControlProposal>
								</smartField:controlProposal>
							</template:if>
						</smartField:SmartField>
					</template:then>
					<template:elseif
						test="{= ${dataField>RecordType} === 'com.sap.vocabularies.UI.v1.DataField' &amp;&amp; !${path: 'dataFieldValue>', formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.isImageUrl'}}">
						<smartField:SmartField value="{path: 'dataField>Value', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" contextEditable="true" editable="{ui>/editable}"
												ariaLabelledBy="{columnId>id}">
							<smartField:configuration>
								<smartField:Configuration displayBehaviour="{parts: [{path: 'dataField>'}, {path: 'entitySet>'}, {path: 'dataFieldTarget>Data'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getTextArrangementForSCFields'}"/>
							</smartField:configuration>
							<template:if test="{= ${dataField>Criticality}}">
								<smartField:controlProposal>
									<smartField:ControlProposal>
										<smartField:objectStatus>
											<smartField:ObjectStatus criticality="{path: 'dataField>Criticality', formatter: 'sap.ui.model.odata.AnnotationHelper.simplePath'}"
																	criticalityRepresentationType="{= (${dataField>CriticalityRepresentation/EnumMember} === 'com.sap.vocabularies.UI.v1.CriticalityRepresentationType/WithoutIcon') ? 'WithoutIcon' : 'WithIcon'}"
																	ariaLabelledBy="{columnId>id}"/>
										</smartField:objectStatus>
									</smartField:ControlProposal>
								</smartField:controlProposal>
							</template:if>
						</smartField:SmartField>
					</template:elseif>
				</template:if>
			</template:with>
		</template:then>
		<template:else>
		<!--  handle data field which is either semantic key, title or description -->
			<template:if test="{= ${dataField>RecordType} === 'com.sap.vocabularies.UI.v1.DataField' &amp;&amp; (${dataField>Value/Path} === ${targetColumn>})}">
				<template:with path="dataField>Value" helper="sap.ui.model.odata.AnnotationHelper.resolvePath" var="dataFieldValue">
					<VBox class="sapMTableContentMargin">
						<items>
							<template:if test="{path: 'dataFieldValue>', formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.isSmartLink'}">
								<template:then>
									<navpopover:SmartLink class="sapSmartTemplatesListReportFirstText"
										text="{parts: [{path: 'dataFieldValue>'}, {path: 'dataField>'}, {path: 'entityType>'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getColumnCellFirstText'}"
										semanticObject="{path: 'dataFieldValue>com.sap.vocabularies.Common.v1.SemanticObject', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}"
										fieldName="{dataFieldValue>name}"
										additionalSemanticObjects="{path: 'dataFieldValue>', formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getAdditionalSemanticObjects'}"
										emphasized="true"
										visible="{parts: [{path: 'dataFieldValue>'}, {path: 'dataField>'}, {path: 'entityType>'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getColumnCellFirstTextVisibility'}"
										navigationTargetsObtained="._templateEventHandlers.onSemanticObjectLinkNavigationTargetObtainedSmartLink"
										ariaLabelledBy="{columnId>id}">
										<navpopover:customData>
											<core:CustomData key="LinkDescr"
												value="{parts: [{path: 'dataFieldValue>'}, {path: 'dataField>'}, {path: 'entityType>'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getColumnCellSecondText'}"/>
										</navpopover:customData>
									</navpopover:SmartLink>
								</template:then>
								<template:else>									
									<ObjectIdentifier 
                                            title="{parts: [{path: 'dataFieldValue>'}, {path: 'dataField>'}, {path: 'entityType>'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getColumnCellFirstText'}"
                                            visible="{parts: [{path: 'dataFieldValue>'}, {path: 'dataField>'}, {path: 'entityType>'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getColumnCellFirstTextVisibility'}"
                                            ariaLabelledBy="{columnId>id}"/>
								</template:else>
							</template:if>
							<FormattedText htmlText="&lt;em&gt;{path:'i18n>NEW_OBJECT', formatter:'jQuery.sap.encodeHTML'}&lt;/em&gt;"
								visible="{parts: [{path: 'dataFieldValue>'}, {path: 'dataField>'}, {path: 'entityType>'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getHeaderVisibility'}"/>
							<Text class="sapUiTinyMarginTop"
								text="{parts: [{path: 'dataFieldValue>'}, {path: 'dataField>'}, {path: 'entityType>'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getColumnCellSecondText'}"
								visible="{parts: [{path: 'dataFieldValue>'}, {path: 'dataField>'}, {path: 'entityType>'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getColumnCellSecondTextVisibility'}"/>
							<core:Fragment fragmentName="sap.suite.ui.generic.template.ListReport.view.fragments.DraftInfoBox" type="XML"/>
						</items>
					</VBox>
				</template:with>
			</template:if>
		</template:else>
	</template:if>

	<!-- handle data field with images -->
	<template:if test="{= ${dataField>RecordType} === 'com.sap.vocabularies.UI.v1.DataField'}">
		<template:with path="dataField>Value" helper="sap.ui.model.odata.AnnotationHelper.resolvePath" var="dataFieldValue">
			<template:if test="{path: 'dataFieldValue>', formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.isImageUrl'}">
				
				<f:Avatar 
					src="{parts:[{path: 'dataField>Value'}, {path: 'parameter>/appComponentName'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.formatImageUrl'}"
					displaySize="S"
					displayShape="Square"
					ariaLabelledBy="{columnId>id}">
				</f:Avatar>
					
			</template:if>
		</template:with>
	</template:if>		
	
	<!-- ObjectPage Self-Linking -->
	<template:if test="{= (${dataField>RecordType} === 'com.sap.vocabularies.UI.v1.DataFieldWithNavigationPath')}">
		<template:then>
			<smartField:SmartField
				value="{parts: [{path: 'dataField>'}, {path: 'listEntitySet>'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getLinkTextForDFwithIBN'}"
				editable="{ui>/editable}" press="._templateEventHandlers.onDataFieldWithNavigationPath"
				ariaLabelledBy="{columnId>id}">
				<smartField:customData>
					<core:CustomData key="Target" value="{dataField>Target/NavigationPropertyPath}"/>
				</smartField:customData>
			</smartField:SmartField>
		</template:then>
	</template:if>
	<!-- handle inline actions -->
	<template:if
		test="{= (${dataField>RecordType} === 'com.sap.vocabularies.UI.v1.DataFieldForAction' || ${dataField>RecordType} === 'com.sap.vocabularies.UI.v1.DataFieldForIntentBasedNavigation') &amp;&amp; ${dataField>Inline/Bool} === 'true'}">
		<template:then>
			<core:Fragment fragmentName="sap.suite.ui.generic.template.fragments.InlineButton" type="XML"/>
		</template:then>
	</template:if>
	<!--handle DataFieldWithIntentBasedNavigation -->
	<template:if test="{= (${dataField>RecordType} === 'com.sap.vocabularies.UI.v1.DataFieldWithIntentBasedNavigation')}">
		<template:then>
			<Link
				text="{parts: [{path: 'dataField>'}, {path: 'listEntitySet>'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getLinkTextForDFwithIBN'}"
				press="._templateEventHandlers.onDataFieldWithIntentBasedNavigation" wrapping="true"
				ariaLabelledBy="{columnId>id}">
				<customData>
					<core:CustomData key="SemanticObject" value="{dataField>SemanticObject/String}"/>
					<core:CustomData key="Action" value="{dataField>Action/String}"/>
				</customData>
			</Link>
		</template:then>
	</template:if>

	<template:if test="{= ${dataField>RecordType} === 'com.sap.vocabularies.UI.v1.DataFieldForAnnotation'}">
		<template:then>
			<!-- Handle ContactPopUp Over  -->
			<template:if test="{= ${dataField>Target/AnnotationPath}.indexOf('com.sap.vocabularies.Communication.v1.Contact') >= 0}">
				<template:with path="dataField>Target" helper="sap.ui.model.odata.AnnotationHelper.resolvePath" var="contact">
					<Link
						binding="{= ${ path: 'dataField>Target/AnnotationPath'}.indexOf('/') > -1 ? '{' + ${path: 'dataField>Target/AnnotationPath'}.slice(0, ${ path: 'dataField>Target/AnnotationPath'}.indexOf('/')) + '}' : null}"
						text="{path: 'contact>fn', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" press="._templateEventHandlers.onContactDetails"
						ariaLabelledBy="{columnId>id}">
						<customData>
							<core:CustomData key="Location" value="SmartTable"/>
							<core:CustomData key="contactDetails" value="{= ${path: 'contact>', formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getCustomDataForContactPopup'}}"/>
						</customData>
					</Link>
				</template:with>
			</template:if>
			
			<!-- handle smart micro chart -->
			<template:if test="{= ${dataField>Target/AnnotationPath}.indexOf('com.sap.vocabularies.UI.v1.Chart') >= 0}">
				<template:then>
					<template:with path="dataField>Target" helper="sap.ui.model.odata.AnnotationHelper.gotoEntitySet" var="annotation">
						<VBox class="sapMTableContentMargin">
							<smc:SmartMicroChart
								entitySet="{parts: [{path: 'annotation>'}, {path: 'entitySet>'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getEntitySetName'}"
								chartBindingPath="{= ${ path: 'dataField>Target/AnnotationPath'}.indexOf('/') > -1 ? ${path: 'dataField>Target/AnnotationPath'}.slice(0, ${ path: 'dataField>Target/AnnotationPath'}.indexOf('/')) : null}"
								enableAutoBinding="{= ${ path: 'dataField>Target/AnnotationPath'}.indexOf('/') > -1 ? true : false}">
								<smc:customData>
									<core:CustomData key="chartQualifier" value="{= ${dataField>Target/AnnotationPath}.split('#')[1]}"/>
								</smc:customData>
							</smc:SmartMicroChart>
						</VBox>
					</template:with>
				</template:then>
				<template:else>
					<!-- handle rating and progress indicators -->
					<template:with path="dataField>Target" helper="sap.ui.model.odata.AnnotationHelper.resolvePath" var="dataFieldTarget">
						<template:if test="{= ${dataFieldTarget>Visualization}}">
							<template:then>
								<template:if test="{= ${dataFieldTarget>Visualization/EnumMember} === 'com.sap.vocabularies.UI.v1.VisualizationType/Rating'}">
									<template:then>
										<template:with path="dataFieldTarget>Value" helper="sap.ui.model.odata.AnnotationHelper.resolvePath" var="value">
											<!--Due to SideEffect issues the RatingIndicator is not  editable -->
											<VBox class="sapMTableContentMargin">
												<template:if test="{= ${parameter>/isFiori3Enabled}}">
													<template:then>
														<RatingIndicator enabled="true" editable="false" maxValue="{path: 'dataFieldTarget>TargetValue', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}"
															binding="{= ${ path: 'dataField>Target/AnnotationPath'}.indexOf('/') > -1 ? '{' + ${path: 'dataField>Target/AnnotationPath'}.slice(0, ${ path: 'dataField>Target/AnnotationPath'}.indexOf('/')) + '}' : null}"
															value="{parts: [{path:'dataFieldTarget>Value'}, {value: 'OneWay'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getDataFieldValue'}"
															ariaLabelledBy="{columnId>id}"/>
													</template:then>
													<template:else>
														<RatingIndicator enabled="false" maxValue="{path: 'dataFieldTarget>TargetValue', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}"
															binding="{= ${ path: 'dataField>Target/AnnotationPath'}.indexOf('/') > -1 ? '{' + ${path: 'dataField>Target/AnnotationPath'}.slice(0, ${ path: 'dataField>Target/AnnotationPath'}.indexOf('/')) + '}' : null}"
															value="{parts: [{path:'dataFieldTarget>Value'}, {value: 'OneWay'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.getDataFieldValue'}"
															ariaLabelledBy="{columnId>id}"/>
												</template:else>
											</template:if>
											</VBox>
										</template:with>
									</template:then>
									<template:elseif test="{= ${dataFieldTarget>Visualization/EnumMember} === 'com.sap.vocabularies.UI.v1.VisualizationType/Progress'}">
										<template:with path="dataFieldTarget>Value" helper="sap.ui.model.odata.AnnotationHelper.resolvePath" var="value">
											<VBox class="sapMTableContentMargin">
												<ProgressIndicator
													binding="{= ${ path: 'dataField>Target/AnnotationPath'}.indexOf('/') > -1 ? '{' + ${path: 'dataField>Target/AnnotationPath'}.slice(0, ${ path: 'dataField>Target/AnnotationPath'}.indexOf('/')) + '}' : null}"
													percentValue="{ parts: [{path:'dataFieldTarget>'}, {path:'value>'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.buildExpressionForProgressIndicatorPercentValue' }"
													displayValue="{ parts: [{path:'dataFieldTarget>'}, {path:'value>Org.OData.Measures.V1.Unit'}], formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.buildExpressionForProgressIndicatorDisplayValue'}"
													state="{path:'dataFieldTarget>', formatter: 'sap.suite.ui.generic.template.js.AnnotationHelper.buildExpressionForProgressIndicatorCriticality'}"
													ariaLabelledBy="{columnId>id}">
													<customData>
														<core:CustomData key="Target" value="{= ${path: 'dataFieldTarget>TargetValue', formatter: 'sap.ui.model.odata.AnnotationHelper.format'} }"/>
														<core:CustomData key="UoM" value="{= ${path: 'value>Org.OData.Measures.V1.Unit', formatter: 'sap.ui.model.odata.AnnotationHelper.format'} }"/>
													</customData>
												</ProgressIndicator>
											</VBox>
										</template:with>
									</template:elseif>
								</template:if>
							</template:then>
						</template:if>
					</template:with>
				</template:else>
			</template:if>		
		</template:then>
	</template:if>
</core:FragmentDefinition>