<core:FragmentDefinition
        xmlns="sap.m"
        xmlns:core="sap.ui.core"
        xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1"
        xmlns:build="sap.build"
        xmlns:sfi="sap.ui.comp.smartfield"
        xmlns:navpopover="sap.ui.comp.navpopover"
        xmlns:micro="sap.suite.ui.microchart">

    <items>
        <CustomListItem
                id="listItem"
                type="Active"
                press="onListItemPress">
            <HBox class="sapOvpBarListHBox sapOvpExtendedBarListHBox">
                <VBox class="sapOvpBarListVBoxLeft">
                    <!-- if manifest Property showLineItemDetail is set to true then the first data field will be a Link to show the Line Item Details-->
                    <template:if
                            test="{= ${ovpCardProperties>/showLineItemDetail} === true}">
                        <template:then>
                            <VBox>
                                <core:Fragment
                                        fragmentName="sap.ovp.cards.generic.LineItemDetails"
                                        type="XML"/>
                                <Link
                                        class="sapOvpBarListDataField sapOvpOverflowEllipsisDataField sapOvpBarListTitle"
                                        text="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/firstDataFieldIndex'}], formatter: 'sap.ovp.cards.AnnotationHelper.formatDataFieldValueOnIndex'}"
                                        press="onContactDetailsLinkPress">
                                </Link>
                            </VBox>
                        </template:then>
                        <!-- if first data field contain semantic object then smartlink to show semantic object info else  first data field value -->
                    <template:elseif
                            test="{parts:[{path:'entitySet>'}, {path:'lineItem>'}], formatter: 'sap.ovp.cards.AnnotationHelper.semanticObjectOfFirstDataField'}">
                            <navpopover:SmartLink
                                    class="sapOvpExtendedBarListFirstDataField sapOvpOverflowEllipsisDataField"
                                    text="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/firstDataFieldIndex'}], formatter: 'sap.ovp.cards.AnnotationHelper.formatDataFieldValueOnIndex'}"
                                    semanticObject="{parts:[{path:'entitySet>'}, {path:'lineItem>'}], formatter: 'sap.ovp.cards.AnnotationHelper.semanticObjectOfFirstDataField'}"
                                    contactAnnotationPath="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/firstDataFieldIndex'}], formatter: 'sap.ovp.cards.AnnotationHelper.checkNavTargetForContactAnno'}" enableAvailableActionsPersonalization="false"
									forceLinkRendering="{parts: [{path: 'entitySet>'}], formatter: 'sap.ovp.cards.AnnotationHelper.checkForContactAnnotation'}">
                            </navpopover:SmartLink>
                        </template:elseif>
                        <template:else>
                            <Text
                                    id="DataField1"
                                    class="sapOvpExtendedBarListFirstDataField sapOvpOverflowEllipsisDataField"
                                    text="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/firstDataFieldIndex'}], formatter: 'sap.ovp.cards.AnnotationHelper.formatDataFieldValueOnIndex'}"/>
                        </template:else>
                    </template:if>
                    <!-- if second data field contain semantic object then smartlink to show semantic object info else  second data field value -->
                    <template:if
                            test="{parts:[{path:'entitySet>'}, {path:'lineItem>'}], formatter: 'sap.ovp.cards.AnnotationHelper.semanticObjectOfSecondDataField'}">
                        <template:then>
                            <navpopover:SmartLink
                                    class="sapOvpExtendedBarListFirstDataField sapOvpOverflowEllipsisDataField"
                                    text="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/secondDataFieldIndex'}], formatter: 'sap.ovp.cards.AnnotationHelper.formatDataFieldValueOnIndex'}"
                                    semanticObject="{parts:[{path:'entitySet>'}, {path:'lineItem>'}], formatter: 'sap.ovp.cards.AnnotationHelper.semanticObjectOfSecondDataField'}"
                                    contactAnnotationPath="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/secondDataFieldIndex'}], formatter: 'sap.ovp.cards.AnnotationHelper.checkNavTargetForContactAnno'}" enableAvailableActionsPersonalization="false"
									forceLinkRendering="{parts: [{path: 'entitySet>'}], formatter: 'sap.ovp.cards.AnnotationHelper.checkForContactAnnotation'}">
                            </navpopover:SmartLink>
                        </template:then>
                        <template:else>
                            <Text
                                    id="DataField2"
                                    class="sapOvpBarListDataField sapOvpBarListSubDataField sapOvpExtendedBarListBlock sapOvpOverflowEllipsisDataField"
                                    text="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/secondDataFieldIndex'}], formatter: 'sap.ovp.cards.AnnotationHelper.formatDataFieldValueOnIndex'}"/>
                        </template:else>
                    </template:if>

                    <layoutData>
                        <FlexItemData
                                growFactor="1"/>
                    </layoutData>
                    <micro:ComparisonMicroChart id="BarChartDataPoint" class="sapOvpBarListComparisonMicroChartAlignment" width="100%" height="1rem"
                            colorPalette="{path: 'lineItem>', formatter: 'sap.ovp.cards.AnnotationHelper.colorPaletteForComparisonMicroChart'}"
                            minValue="{minMaxModel>/minValue}"
                            maxValue="{minMaxModel>/maxValue}">
                        <micro:data>
                            <micro:ComparisonMicroChartData displayValue=" "
                                                            value="{= '{path: \'' + ${path: 'lineItem>', formatter: 'sap.ovp.cards.AnnotationHelper.getFirstDataPointValue'} + '\', formatter: \'.returnBarChartValue\'}' }"
                                                            color="{path: 'lineItem>', formatter: 'sap.ovp.cards.AnnotationHelper.formatFirstDataPointColor'}">
                            </micro:ComparisonMicroChartData>
                        </micro:data>
                    </micro:ComparisonMicroChart>

                </VBox>
                <VBox class="{= ${path: 'lineItem>', formatter: 'sap.ovp.cards.AnnotationHelper.getDataPointsCount'} > 0 ? 'sapOvpBarListVBoxRight' : 'sapOvpListEmptyField'}">
                    <!-- if contact annotation then show link to display contact detail else second data point value -->
                    <template:if test="{= ${path: 'lineItem>', formatter: 'sap.ovp.cards.AnnotationHelper.isFirstContactAnnotation'} === true}">
                        <template:then>
                            <template:repeat list="{path:'lineItem>'}" var="dataField">
                                <template:if
                                        test="{= ${dataField>RecordType} === 'com.sap.vocabularies.UI.v1.DataFieldForAnnotation'}">
                                    <template:then>
                                        <template:if
                                                test="{= ${dataField>Target/AnnotationPath}.indexOf('com.sap.vocabularies.Communication.v1.Contact') >= 0}">
                                            <template:then>
                                                <template:with path="dataField>Target"
                                                               helper="sap.ui.model.odata.AnnotationHelper.resolvePath"
                                                               var="contact">
                                                    <VBox class="textAlignRight" width="100%">
                                                        <core:Fragment fragmentName="sap.ovp.cards.generic.ContactDetails"
                                                                       type="XML"/>
                                                        <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'}"
                                                              textAlign="Right"
                                                              press="onContactDetailsLinkPress">
                                                        </Link>
                                                    </VBox>
                                                </template:with>
                                            </template:then>
                                        </template:if>
                                    </template:then>
                                </template:if>
                            </template:repeat>
                        </template:then>
                        <template:else>
                            <template:if test="{= ${path: 'lineItem>', formatter: 'sap.ovp.cards.AnnotationHelper.getDataPointsCount'} > 1}" >
                                <ObjectNumber
                                        id="DataPoint2"
                                        class="{= ${path: 'lineItem>', formatter: 'sap.ovp.cards.AnnotationHelper.formatFirstDataPointState'} === 'None' ?
                                            'sapOvpBarListObjectNumber' : 'sapOvpBarListObjectNumber sapOvpBarListObjectNumberWithoutState'} sapOvpObjectNumber"
                                        textAlign="End"
                                        number="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/secondDataPointIndex'}, {path:'ovpConstants>/dontIncludeUOM'}], formatter: 'sap.ovp.cards.AnnotationHelper.formatObjectNumber'}"
                                        unit="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/secondDataPointIndex'}], formatter: 'sap.ovp.cards.AnnotationHelper.formatUnit'}"
                                        state="{path: 'lineItem>', formatter: 'sap.ovp.cards.AnnotationHelper.formatSecondDataPointState'}"/>
                            </template:if>
                        </template:else>
                    </template:if>
                    <template:if test="{= ${path: 'lineItem>', formatter: 'sap.ovp.cards.AnnotationHelper.getDataPointsCount'} > 2}" >
                        <ObjectNumber
                                id="DataPoint3"
                                class="{= ${path: 'lineItem>', formatter: 'sap.ovp.cards.AnnotationHelper.formatFirstDataPointState'} === 'None' ?
                                            'sapOvpBarListObjectNumber' : 'sapOvpBarListObjectNumber sapOvpBarListObjectNumberWithoutState'} sapOvpObjectNumber"
                                textAlign="End"
                                number="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/thirdDataPointIndex'}, {path:'ovpConstants>/dontIncludeUOM'}], formatter: 'sap.ovp.cards.AnnotationHelper.formatObjectNumber'}"
                                unit="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/thirdDataPointIndex'}], formatter: 'sap.ovp.cards.AnnotationHelper.formatUnit'}"
                                state="{path: 'lineItem>', formatter: 'sap.ovp.cards.AnnotationHelper.formatThirdDataPointState'}"/>
                    </template:if>
                    <template:if test="{= ${path: 'lineItem>', formatter: 'sap.ovp.cards.AnnotationHelper.isFirstDataPointPercentageUnit'}}" >
                        <template:then>
                            <ObjectNumber
                                    id="BarChartValue"
                                    class="sapOvpBarListObjectNumber sapOvpBarListObjectNumberPercentage sapOvpObjectNumber"
                                    textAlign="End"
                                    number="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/firstDataPointIndex'}], formatter: 'sap.ovp.cards.AnnotationHelper.formatDataPointValueOnIndex'}"/>
                        </template:then>
                        <template:else>
                            <ObjectNumber
                                    id="BarChartStateValue"
                                    class="sapOvpBarListObjectNumber valueStateText "
                                    textAlign="End"
                                    number="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/firstDataPointIndex'}, {path:'ovpConstants>/dontIncludeUOM'}], formatter: 'sap.ovp.cards.AnnotationHelper.formatObjectNumber'}"
                                    unit="{parts:[{path:'lineItem>'}, {path:'ovpConstants>/firstDataPointIndex'}], formatter: 'sap.ovp.cards.AnnotationHelper.formatUnit'}"
                                    state="{path: 'lineItem>', formatter: 'sap.ovp.cards.AnnotationHelper.formatFirstDataPointState'}">
                            </ObjectNumber>
                        </template:else>
                    </template:if>
                </VBox>
            </HBox>

        </CustomListItem>
    </items>

</core:FragmentDefinition>
