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

<f:if condition="({f:count(subject: allTemplatesOnPage)} > 1) || ({f:count(subject: relevantCategories)} > 1)">
    <div class="form-row">
        <f:if condition="{f:count(subject: allTemplatesOnPage)} > 1">
            <div class="form-group">
                <form action="{f:be.uri(route: 'web_typoscript_constanteditor', parameters: '{id: pageUid}')}" method="post">
                    <label class="form-label" for="selectedTemplate">
                        <f:translate key="LLL:EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf:options.selectedRecord" />
                    </label>
                    <select
                        name="selectedTemplate"
                        id="selectedTemplate"
                        class="form-select"
                        data-global-event="change"
                        data-action-navigate="$data=~s/$value/"
                        data-action-submit="$form"
                    >
                        <f:for each="{allTemplatesOnPage}" as="template">
                            <option
                                value="{template.uid}"
                                {f:if(condition:'{selectedTemplateUid} == {template.uid}', then:'selected="selected"')}
                            >
                                {template.title}
                            </option>
                        </f:for>
                    </select>
                </form>
            </div>
        </f:if>
        <f:if condition="{selectedTemplateUid} > 0 && {f:count(subject: relevantCategories)} > 1">
            <div class="form-group">
                <form action="{f:be.uri(route: 'web_typoscript_constanteditor', parameters: '{id: pageUid}')}" method="post">
                    <label class="form-label" for="selectedCategory">
                        <f:translate key="LLL:EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf:options.selectedCategory" />
                    </label>
                    <select
                        name="selectedCategory"
                        id="selectedCategory"
                        class="form-select"
                        data-global-event="change"
                        data-action-navigate="$data=~s/$value/"
                        data-action-submit="$form"
                    >
                        <f:for each="{relevantCategories}" key="relevantCategoryKey" as="relevantCategory">
                            <option
                                value="{relevantCategoryKey}"
                                {f:if(condition:'{selectedCategory} == {relevantCategoryKey}', then:'selected="selected"')}
                            >
                                {relevantCategory.label} ({relevantCategory.usageCount})
                            </option>
                        </f:for>
                    </select>
                </form>
            </div>
        </f:if>
    </div>
</f:if>

</html>
