<!--
    /**
     * This fragment renders a DataField
     * @param entitySet context to the EntitySet
     * @param dataField context to the DataField
     * @param property context to the Property Path
	 * @param parentControl parentControl of the field
	 * parentControl EnumValues: 'Table', 'Form'
	 * @param wrap wrapping allowed for a field or not
	 * wrap Boolean: true, false
	 * Incoming from Field.fragment.xml
 	 * 	 @param idPrefix default 'F' Prefix for the id
 	 * 	 @param vhIdPrefix default 'FVH' Prefix for the value help id
     * @returns
     */
-->

<core:FragmentDefinition xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1"
						 xmlns="sap.m"
						 xmlns:u="sap.ui.unified"
						 xmlns:f="sap.f"
						 xmlns:core="sap.ui.core"
						 xmlns:mdcField="sap.ui.mdc.field"
						 xmlns:mdc="sap.ui.mdc"
						 xmlns:mdcLink="sap.ui.mdc.link"
						 xmlns:log="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"
						 template:require="{
							MODEL: 'sap/ui/model/odata/v4/AnnotationHelper',
							COMMON: 'sap/fe/macros/CommonHelper',
							FIELD: 'sap/fe/macros/field/FieldHelper',
							ID: 'sap/fe/macros/StableIdHelper'
						 }">
	<template:with path="property>" helper="FIELD.valueHelpProperty" var="valueHelpProperty">
	<mdc:Field
		core:require="{FieldRuntime: 'sap/fe/macros/field/FieldRuntime'}"
		class="{this>class}"
		id="{= ${this>idPrefix} ? COMMON.getStableId(['F', ${this>idPrefix}, ${property>$Path}]) : undefined }"
		log:sourcePath="/{entitySet>@sapui.name}/{property>$Path@@FIELD.propertyName}"
		value="{property>@@MODEL.format}"
		editMode="{= COMMON.getEditMode(${property>$Path@},${dataField>$Type},${property>$Path@@FIELD.fieldControl},(${entitySet>@com.sap.vocabularies.Common.v1.DraftRoot} || ${entitySet>@com.sap.vocabularies.Common.v1.DraftNode}) ,${this>editMode}, ${this>parentControl}, false, undefined, (${property>$Path@Org.OData.Measures.V1.Unit} &amp;&amp; ${property>$Path@Org.OData.Measures.V1.Unit/$Path@@FIELD.fieldControl}))}"
		width="100%"
		required="{= FIELD.getRequiredForDataField(${property>$Path@@FIELD.fieldControl}, ${this>editMode})}"
		additionalValue="{= !(${property>$Path@Org.OData.Measures.V1.ISOCurrency} || ${property>$Path@Org.OData.Measures.V1.Unit}) ? ${property>$Path@@FIELD.buildExpressionForTextValue} : undefined }"
		display="{= FIELD.getFieldDisplay(
					${property>$Path@},
					${dataField>$Type},
					${property>$Path@@FIELD.fieldControl},
					(${entitySet>@com.sap.vocabularies.Common.v1.DraftRoot} || ${entitySet>@com.sap.vocabularies.Common.v1.DraftNode}),
					${this>editMode},
					${this>parentControl},
					${entitySet>./@},
					(${valueHelpProperty>@com.sap.vocabularies.Common.v1.ValueListReferences} || ${valueHelpProperty>@com.sap.vocabularies.Common.v1.ValueListMapping} || ${valueHelpProperty>@com.sap.vocabularies.Common.v1.ValueList})
				)}"
		multipleLines="{= ${this>wrap} === 'false' ? false : (${property>$Path/$Type} !== 'Edm.String' ? ${property>$Path@com.sap.vocabularies.UI.v1.MultiLineText} :
				(${this>editMode} === 'Display' ? true : (${this>editMode}.indexOf('{') > -1 ? '{= $' + ${this>editMode} + ' === \'Display\' ? true : ' + ${property>$Path@com.sap.vocabularies.UI.v1.MultiLineText} + '}' :
				${property>$Path@com.sap.vocabularies.UI.v1.MultiLineText})))}"
		fieldHelp="{= (${valueHelpProperty>@com.sap.vocabularies.Common.v1.ValueListReferences} ||
				${valueHelpProperty>@com.sap.vocabularies.Common.v1.ValueListMapping} ||
				${valueHelpProperty>@com.sap.vocabularies.Common.v1.ValueList}) ? ID.generate([${this>vhIdPrefix} || 'FVH', ((${property>@@FIELD.propertyName} !== ${valueHelpProperty>@@FIELD.propertyName}) ? (${property>@@FIELD.propertyName} + '::' + ${valueHelpProperty>@@FIELD.propertyName}) : ${valueHelpProperty>@@FIELD.propertyName})]) : undefined }"
		fieldGroupIds="{parts:[{path:'dataField>Value/$Path'}, {path:'entitySet>$Type'}], formatter: 'FIELD.getFieldGroupIds'}"
		change="{= ${this>onChange} || 'FieldRuntime.handleChange($event)' }"
		visible="{= ${dataField>@@.FIELD.getHiddenPathExpression}}"
		validateFieldGroup="FieldRuntime.handleSideEffect($event)">
		<!-- TODO: add one Way Binding to additional Value -->
		<template:if test="{property>$Path@com.sap.vocabularies.Common.v1.SemanticObject}">
			<template:if test="{property>@@FIELD.getNavigationEntity}">
				<template:then>
					<core:Fragment fragmentName="sap.fe.macros.field.QuickViewForm" type="XML"/>
				</template:then>
				<template:else>
					<mdc:fieldInfo>
						<mdcField:FieldInfo>
							<mdcLink:ContentHandler sourceControl="{= ${this>idPrefix} ? COMMON.getStableId(['F', ${this>idPrefix}, ${property>$Path@@.MODEL.value}]) : undefined }">
								<mdcLink:linkHandler sourceControl="{= ${this>idPrefix} ? COMMON.getStableId(['F', ${this>idPrefix}, ${property>$Path@@.MODEL.value}]) : undefined }">
									<mdcLink:FlpLinkHandler
										sourceControl="{= ${this>idPrefix} ? COMMON.getStableId(['F', ${this>idPrefix}, ${property>$Path@@.MODEL.value}]) : undefined }"
										textOfMainItem="{dataField>Value@@MODEL.value}"
										descriptionOfMainItem="{property>$Path@@FIELD.buildExpressionForTextValue}"
										iconOfMainItem="{dataField>IconUrl@@MODEL.value}"
										mainSemanticObject="{property>$Path@com.sap.vocabularies.Common.v1.SemanticObject@@MODEL.value}"
										semanticObjects="{property>$Path@com.sap.vocabularies.Common.v1.SemanticObject@@MODEL.value}">
											<mdcLink:semanticObjectMappings>
												<mdcLink:SemanticObjectMapping semanticObject="{property>$Path@com.sap.vocabularies.Common.v1.SemanticObject@@MODEL.value}">
													<template:repeat list="{property>$Path@com.sap.vocabularies.Common.v1.SemanticObjectMapping}" var="mapping">
														<mdcLink:SemanticObjectMappingItem
															key="{mapping>LocalProperty/$PropertyPath}"
															value="{mapping>SemanticObjectProperty@@MODEL.value}"/>
													</template:repeat>
												</mdcLink:SemanticObjectMapping>
											</mdcLink:semanticObjectMappings>
									</mdcLink:FlpLinkHandler>
								</mdcLink:linkHandler>
							</mdcLink:ContentHandler>
						</mdcField:FieldInfo>
					</mdc:fieldInfo>
				</template:else>
			</template:if>
		</template:if>
		<template:if test="{= ${dataField>$Type} === 'com.sap.vocabularies.UI.v1.DataFieldWithUrl'}">
			<template:then>
				<mdc:fieldInfo>
					<mdcField:FieldInfo>
						<mdcLink:ContentHandler enablePersonalization="false">
							<mdcLink:linkHandler>
								<mdcLink:LinkHandler>
									<mdcLink:LinkItem text="{dataField>Value@@MODEL.value}" href="{dataField>Url@@MODEL.value}" target="_blank"/>
								</mdcLink:LinkHandler>
							</mdcLink:linkHandler>
						</mdcLink:ContentHandler>
					</mdcField:FieldInfo>
				</mdc:fieldInfo>
			</template:then>

			<template:elseif test="{= ${dataField>./@sapui.name} &amp;&amp; ${dataField>./@sapui.name}.indexOf('com.sap.vocabularies.UI.v1.DataPoint') > -1 }">
					<template:with path="dataField>" var="dataPoint">
						<core:Fragment fragmentName="sap.fe.macros.field.DataPoint" type="XML"/>
					</template:with>
			</template:elseif>

			<template:elseif test="{= ${annotationPath>} &amp;&amp; ${annotationPath>}.indexOf('com.sap.vocabularies.UI.v1.DataPoint') > -1 }">
					<template:with path="annotationPath>" var="dataPoint">
						<core:Fragment fragmentName="sap.fe.macros.field.DataPoint" type="XML"/>
					</template:with>
			</template:elseif>

			<template:else>
				<!-- in case of semantic key render object identifier -->
				<template:if test="{= ${property>@@FIELD.isLineItem} &amp;&amp; FIELD.isSemanticKey(${entitySet>./@com.sap.vocabularies.Common.v1.SemanticKey}, ${property>}) }">
					<VBox>
						<Label text="{= ${entitySet>@com.sap.vocabularies.Common.v1.DraftRoot} ? FIELD.getSemanticKeyTitle((${property>$Path@com.sap.vocabularies.Common.v1.Text} &amp;&amp; ${property>$Path@@FIELD.buildExpressionForTextValue}), ${property>@@MODEL.value}, ${dataField>@sapui.name}) : (${property>$Path@com.sap.vocabularies.Common.v1.Text} ? ${property>$Path@@FIELD.buildExpressionForTextValue} : (${property>@@MODEL.value} || '{' + ${dataField>@sapui.name} + '}'))}"
							design="Bold"/>
							<template:if test="{entitySet>@com.sap.vocabularies.Common.v1.DraftRoot}">
								<!-- TODO: temp solution only, try to use the mdc_Link-->
								<ObjectMarker type="{= !%{IsActiveEntity} ? 'Draft' : (%{HasDraftEntity} ? (%{DraftAdministrativeData/InProcessByUser} ? 'Locked' : 'Unsaved') : 'Flagged') }"
									visibility="{= !%{HasDraftEntity} ? 'TextOnly' : 'IconAndText' }"
									class="sapUiTinyMarginBottom"
									press="FieldRuntime.onDraftLinkPressed($event, '{entitySet>@sapui.name}')"
									visible="{= !${IsActiveEntity} || ${HasDraftEntity}}"
									additionalInfo="{path: 'entitySet>$Type', formatter: 'FIELD.getBindingForDraftAdminBlockInline'}"/>
							</template:if>
					</VBox>
				</template:if>

				<template:if test="{property>$Path@com.sap.vocabularies.UI.v1.IsImageURL}">
					<f:Avatar
						src="{property>@@MODEL.value}"
						displaySize="S"
						class="sapUiSmallMarginEnd"
						displayShape="Square">
					</f:Avatar>
				</template:if>

				<template:if test="{= ${property>$Path/$Type} === 'Edm.Stream'}">
					<HBox>
						<core:Icon src="sap-icon://document" class="sapUiSmallMarginEnd"/>
						<Link text="{this.i18n>field.PREVIEW}" target="_blank" href="{property>@@MODEL.value}" />
					</HBox>
				</template:if>

				<!-- Object Status -->
				<template:if test="{path: 'dataField>Criticality/$Path'}">
					<ObjectStatus
							icon="{=(${dataField>CriticalityRepresentation/$EnumMember} === 'com.sap.vocabularies.UI.v1.CriticalityRepresentationType/WithoutIcon') ? '' : ${path: 'dataField>Criticality/$Path', formatter: 'FIELD.buildExpressionForCriticalityIcon'}}"
							state="{path: 'dataField>Criticality/$Path', formatter: 'FIELD.buildExpressionForCriticalityColor'}"
							text="{path: '$field>/conditions', type: 'sap.ui.mdc.field.ConditionsType', mode : 'OneWay'}"/>
				</template:if>
			</template:else>
		</template:if>
	</mdc:Field>
	</template:with>
</core:FragmentDefinition>
