<core:FragmentDefinition
    xmlns="sap.m"
    xmlns:core="sap.ui.core"
    xmlns:dnd="sap.ui.core.dnd"
    xmlns:grid="sap.ui.layout.cssgrid"
    xmlns:l="sap.ui.layout"
    xmlns:layout="sap.ui.layout"
    xmlns:f="sap.ui.layout.form"
    core:require="{
    format: 'sap/mcsuite/model/Format', 
    translate: 'sap/mcsuite/model/Translate', 
    utils: 'sap/mcsuite/model/Utils'
  }"  
>
    <Dialog
        draggable="true"
        contentHeight="auto"
        contentWidth="auto"
        showHeader="false"
        class="mc-dialog"
        >
        <HBox
            alignItems="Center"
            justifyContent="Center"
            class='mc-dialog-toolButtons'
        >
            <Button
                class='transparent-button'
                icon="sap-icon://fa-light/copy"
                type="Unstyled"
                press="copyDialogData"
            />
            <Button
                class='transparent-button'
                icon="sap-icon://fa-light/arrow-up-right-from-square"
                type="Unstyled"
                press="taskNav"
            >
                <customData>
                    <core:CustomData
                        key="module"
                        value="clients"
                    />
                    <core:CustomData
                        key="task"
                        value="clients_show"
                    />
                    <core:CustomData
                        key="field"
                        value="id"
                    />
                    <core:CustomData
                        key="value"
                        value="{id}"
                    />
                </customData>
            </Button>
        </HBox>
    <VBox class="mc-dialog-header" alignItems="Stretch" justifyContent="SpaceBetween">
        <grid:CSSGrid gridTemplateColumns="2fr 5fr" width="90%">
            <HBox alignItems="Start" justifyContent="Center">
                <Avatar 
                    src="sap-icon://fa-light/sitemap"
                    displaySize="S"
                    class="sapUiTinyMarginEnd"
                ></Avatar>
            </HBox>
            <VBox alignItems="Start" justifyContent="Center">   
                <HBox alignItems="Center" justifyContent="Start" height="1rem">
                    <Title 
                        text="{name}" level="H3"
                    ></Title>
                    
                </HBox>
                <Text 
                    text="{_cat_id/name}"
                ></Text>
            </VBox>
            
        <!-- </HBox> -->    
        </grid:CSSGrid>
            <VBox alignItems="Center" justifyContent="Center" visible="{= %{parts: [{path: 'id'}, {value: 'crm_clients_bs'},  {value: 'crm_shops_bs'}], formatter: '.getCount'} > 0}">
                <core:Icon 
                    class="property-icon"
                    src="sap-icon://fa-light/building"
                ></core:Icon>
                <HBox items='{path: "crm_shops_bs", templateShareable: false}' wrap="NoWrap" alignItems="Center" justifyContent="Start">
                <Text 
                    text="{sap_number}"
                    class='sapUiTinyMarginEnd'
                ></Text>
                </HBox>
            </VBox>
        <VBox class='mc-dialog-content' items="{path: 'erp_jobs_bs', templateShareable: false, length: 3, sorter: {path: '_cat_id/pos', descending: false}}">
            <VBox class='sapUiSmallMarginBottom'>   
                <HBox alignItems="Center" justifyContent="Start" width="100%">
                <core:Icon src="{='sap-icon://fa-light/' + ${_cat_id/icon}}" size="1rem" color="{_cat_id/color}" class='sapUiSmallMarginEnd'></core:Icon>
                    <Text 
                        text="{name}"
                    ></Text>
                </HBox>
                <VBox items="{path: 'erp_jobs_dt', templateShareable: false}" class='sapUiSmallMarginBegin'>
                    <VBox width="100%">
                        <HBox visible="{= %{path: '_object', targetType: 'object'} !== null}">
                            <core:Icon
                                src="sap-icon://fa-solid/circle"
                                size="0.7rem"
                                class='sapUiTinyMarginEnd property-icon'
                            />
                            <Text text="{name}" />
                            <Text
                                text='-'
                                visible="{= %{path: '_object', targetType: 'object'} !== null}"
                            />
                            <Link
                                visible="{= ${path: '_object', targetType: 'object'} !== null}"
                                href="{='tel:' + JSON.parse(${_object}).contact_information.phone}"
                                text="{=JSON.parse(${_object}).contact_information.phone}"
                            />
                        </HBox>
                        <HBox visible="{= %{path: '_object', targetType: 'object'} === null}" items="{path: '_contact_id/crm_contacts_dt', templateShareable: false, length: 1, filters: [{path: 'type', operator: 'EQ', value1: 'INTERN'}]}">
                            <HBox class='sapUiTinyMarginBegin'>
                            
                            <Text text="{_contact_id/name}" />
                            <Text
                                text="-" class='sapUiTinyMarginBegin sapUiTinyMarginEnd'
                            />
                            <Link
                                href="{= %{path: 'phone', targetType:  'string'} !== '' ? ('tel:' + ${phone}) : ('mailto:' + ${email})}"
                                text="{= %{path: 'phone', targetType:  'string'} !== '' ? ${phone} : ${email}}"
                            />
                            </HBox>
                        </HBox>
                        </VBox>
                </VBox>
            </VBox>
        </VBox>
    
    </VBox>
        
    </Dialog>
</core:FragmentDefinition>
