<html
    xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
    data-namespace-typo3-fluid="true"
>

<f:layout name="Module"/>

<f:section name="Before">
    <f:asset.module identifier="@typo3/backend/context-menu.js"/>
    <f:asset.module identifier="@typo3/backend/element/immediate-action-element.js"/>
    <f:asset.module identifier="@typo3/backend/utility/collapse-state-persister.js"/>
    <f:asset.module identifier="@typo3/tstemplate/constant-editor.js"/>
    <f:variable name="args" value="{0: 'web', 1: pageUid}" />
    <typo3-immediate-action
        action="TYPO3.Backend.Storage.ModuleStateStorage.update"
        args="{args -> f:format.json() -> f:format.htmlspecialchars()}"
    ></typo3-immediate-action>
</f:section>

<f:section name="Content">
    <h1>
        <f:if condition="{templateTitle}">
            <f:then>
                <f:translate
                    key="LLL:EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf:submodule.titleWithRecord"
                    arguments="{
                        0: '{templateTitle}'
                    }"
                />
            </f:then>
            <f:else>
                <f:translate key="LLL:EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf:submodule.title" />
            </f:else>
        </f:if>
    </h1>

    <f:if condition="{selectedTemplateUid} > 0">
        <p><f:translate key="LLL:EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf:submodule.description" /></p>
    </f:if>

    <f:comment><!-- Options --></f:comment>
    <f:render
        partial="ConstantEditorOptions"
        arguments="{
            allTemplatesOnPage: allTemplatesOnPage,
            pageUid: pageUid,
            selectedTemplateUid: selectedTemplateUid,
            relevantCategories: relevantCategories,
            selectedCategory: selectedCategory
        }"
    />

    <f:if condition="{selectedTemplateUid} > 0">
        <f:comment><!-- Main form --></f:comment>
        <f:if condition="!{relevantCategories}">
            <f:then>
                <f:be.infobox message="{f:translate(key:'LLL:EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf:infobox.message.noConstants')}" state="{f:constant(name: 'TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper::STATE_INFO')}" />
            </f:then>
            <f:else>
                <f:render partial="ConstantEditorFields" arguments="{_all}" />
            </f:else>
        </f:if>
    </f:if>

    <f:if condition="{selectedTemplateUid} == -1">
        <f:be.infobox
            state="{f:constant(name: 'TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper::STATE_INFO')}"
            title="{f:translate(key: 'LLL:EXT:tstemplate/Resources/Private/Language/locallang_info.xlf:noConstantsButSiteSettings.title')}"
        >
            <p>
                <f:translate
                    key="LLL:EXT:tstemplate/Resources/Private/Language/locallang_info.xlf:noConstantsButSiteSettings.message"
                    arguments="{
                        0: '{templateRecord.site.identifier}'
                    }"
                />
            </p>
            <f:variable name="returnUrl">{f:be.uri(route: 'web_typoscript_constanteditor', parameters: {id: pageUid})}</f:variable>
            <f:be.link route="site_settings.edit" parameters="{site: templateRecord.site.identifier, returnUrl: returnUrl}" class="btn btn-default">
                <f:translate key="LLL:EXT:tstemplate/Resources/Private/Language/locallang_info.xlf:btn.editSiteSettings"/>
            </f:be.link>
        </f:be.infobox>
    </f:if>
</f:section>

</html>
