{namespace n=Neos\Neos\ViewHelpers}
{namespace vh=Newland\NeosViewHelpers\ViewHelpers}
{namespace map=Newland\Toubiz\Map\Neos\ViewHelpers}

<f:if condition="{latitude} && {longitude}">
    <f:then>
        <div class="tb-article__content-block">
            <a href="#0" class="tb-static-map" itemtype="http://schema.org/Map">
                <vh:render section="MapContent" arguments="{_all}"/>
            </a>
        </div>
    </f:then>
    <f:else if="!{n:rendering.inBackend(node: node)}">
        <!-- Map:Location node not rendered: Missing coordinates -->
    </f:else>
    <f:else if="!{latitude} || !{longitude}">
        <vh:render section="coordinatesMissing" arguments="{_all}" />
    </f:else>
</f:if>

<f:section name="MapContent">
    <vh:render section="IconSprite"/>

    <map:staticMap
        latitude="{latitude}"
        longitude="{longitude}"
        node="{node}"
        configurationPath="Newland.Toubiz.Map.Neos.location.map"
    />

    <f:comment>
        <!-- Link to map page is not good enough. Until we can preselect a map marker on that page, we'll hide the link. -->
        <f:if condition="{detailMap}">
            <n:link.node node="{detailMap}">
                <f:translate id="detailedMap" source="NodeTypes/Location" package="Newland.Toubiz.Map.Neos"/>
            </n:link.node>
        </f:if>
    </f:comment>
</f:section>

<f:section name="IconSprite">
    <svg style="display: none;">
        <symbol id="tb-map-geolocation" viewBox="0 0 512 512"><path d="M256 168c-48.6 0-88 39.4-88 88s39.4 88 88 88 88-39.4 88-88-39.4-88-88-88zm0 128c-22.06 0-40-17.94-40-40s17.94-40 40-40 40 17.94 40 40-17.94 40-40 40zm240-64h-49.66C435.49 145.19 366.81 76.51 280 65.66V16c0-8.84-7.16-16-16-16h-16c-8.84 0-16 7.16-16 16v49.66C145.19 76.51 76.51 145.19 65.66 232H16c-8.84 0-16 7.16-16 16v16c0 8.84 7.16 16 16 16h49.66C76.51 366.81 145.19 435.49 232 446.34V496c0 8.84 7.16 16 16 16h16c8.84 0 16-7.16 16-16v-49.66C366.81 435.49 435.49 366.8 446.34 280H496c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zM256 400c-79.4 0-144-64.6-144-144s64.6-144 144-144 144 64.6 144 144-64.6 144-144 144z"/></symbol>
    </svg>
</f:section>

<f:section name="apiKeyMissing">
    <div style="border: 5px solid yellow; padding: 25px; margin: 25px;">
        <h1>
            <f:translate id="error.apiKeyMissing.header"
                         source="NodeTypes/Location"
                         package="Newland.Toubiz.Map.Neos"/>
        </h1>
        <p>
            <f:format.raw>
                <f:translate id="error.apiKeyMissing.body"
                             source="NodeTypes/Location"
                             package="Newland.Toubiz.Map.Neos"/>
            </f:format.raw>
        </p>
    </div>
</f:section>

<f:section name="coordinatesMissing">
    <div style="border: 5px solid yellow; padding: 25px; margin: 25px;">
        <h1>
            <f:translate id="error.coordinatesMissing.header"
                         source="NodeTypes/Location"
                         package="Newland.Toubiz.Map.Neos"/>
        </h1>
        <p>
            <f:format.raw>
                <f:translate id="error.coordinatesMissing.body"
                             source="NodeTypes/Location"
                             package="Newland.Toubiz.Map.Neos"
                             arguments="{ 0: pageName, 1: pagePath }"/>
            </f:format.raw>
        </p>
    </div>
</f:section>
