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

<f:asset.module identifier="@typo3/backend/tree/tree-node-toggle.js"/>
<f:asset.module identifier="@typo3/backend/utility/collapse-state-persister.js"/>

<f:comment><!-- This is a template that calls itself recursive for sub nodes. --></f:comment>

<f:if condition="{tree.children}">
    <f:for each="{tree.nextChild}" as="child">
        <li>
            <f:if condition="{child.children}">
                <typo3-backend-tree-node-toggle
                    class="treelist-control treelist-control-collapsed"
                    data-bs-toggle="collapse"
                    data-bs-target="#collapse-list-{child.identifier}"
                    aria-expanded="false">
                </typo3-backend-tree-node-toggle>
            </f:if>
            <div class="row justify-content-between">
                <div class="col">
                    <div class="row row-cols-auto justify-content-md-between">
                        <div class="col col-12 col-lg-auto">
                            <span class="treelist-group treelist-group-monospace">
                                <span class="treelist-label">
                                    <f:if condition="{child.type} == 'Segment'">
                                        <f:then>
                                            <f:translate key="LLL:EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf:tree.child.type.Segment" />
                                        </f:then>
                                        <f:else if="{child.type} == 'DefaultTypoScriptMagicKey'">
                                            <f:translate key="LLL:EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf:tree.child.type.DefaultTypoScriptMagicKey_formlabel" />
                                        </f:else>
                                        <f:else if="{child.type} == 'Condition'">
                                            {child.lineStream}
                                        </f:else>
                                        <f:else if="{child.type} == 'ConditionElse'">
                                            {child.lineStream}
                                        </f:else>
                                        <f:else if="{child.type} == 'ConditionStop'">
                                            {child.lineStream}
                                        </f:else>
                                        <f:else>{child.name}</f:else>
                                    </f:if>
                                </span>
                            </span>
                        </div>
                        <div class="col col-12 col-lg-auto text-md-end">
                            <f:comment><!-- Hand {child.type} over to f:translate and add locallang.xlf entries when Include classes stabilized. --></f:comment>
                            <f:if condition="{child.sysTemplateRecord}">
                                <f:then>
                                    <span class="badge">
                                        <f:translate key="LLL:EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf:tree.child.sysTemplateRecord" arguments="{0: '{child.pid}'}" />
                                    </span>
                                </f:then>
                                <f:else if="{child.type} != 'Segment'">
                                    <span class="badge">
                                        <f:translate key="LLL:EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf:tree.child.type.{child.type}" />
                                    </span>
                                </f:else>
                            </f:if>
                            <f:if condition="{child.root}">
                                <span class="badge badge-info">
                                    <f:translate key="LLL:EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf:tree.child.setting.root" />
                                </span>
                            </f:if>
                            <f:if condition="{child.clear}">
                                <span class="badge badge-info">
                                    <f:translate key="LLL:EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf:tree.child.setting.clear" />
                                </span>
                            </f:if>
                        </div>
                    </div>
                </div>
                <div class="col col-auto text-end">
                    <div class="btn-group tstemplate-tree-btn-group">
                        <f:be.link
                            route="web_typoscript_analyzer.source"
                            parameters="{id: pageUid, includeType: type, identifier: child.identifier}"
                            additionalAttributes="{'data-modal-title': child.name}"
                            class="btn btn-default btn-sm t3js-typoscript-analyzer-modal{f:if(condition:'!{child.lineStream}', then:' disabled')}"
                            title="{f:translate(key: 'LLL:EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf:tree.child.btn.sourceCode')}"
                        >
                            <core:icon identifier="{f:if(condition:'{child.lineStream}', then:'actions-variable', else: 'empty-empty')}" />
                        </f:be.link>
                        <f:be.link
                            route="web_typoscript_analyzer.sourceWithIncludes"
                            parameters="{id: pageUid, includeType: type, identifier: child.identifier}"
                            additionalAttributes="{'data-modal-title': '{child.name} (with resolved includes)'}"
                            class="btn btn-default btn-sm t3js-typoscript-analyzer-modal{f:if(condition:'!{child.children}', then:' disabled')}"
                            title="{f:translate(key: 'LLL:EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf:tree.child.btn.sourceCodeWithResolvedIncludes')}"
                        >
                            <core:icon identifier="{f:if(condition:'{child.children}', then:'actions-variable-select', else: 'empty-empty')}" />
                        </f:be.link>
                    </div>
                </div>
            </div>

            <f:if condition="{child.children}">
                <div
                    class="treelist-collapse collapse"
                    id="collapse-list-{child.identifier}"
                    data-persist-collapse-state="true"
                    data-persist-collapse-state-suffix="typoscript-include-{type}"
                    data-persist-collapse-state-if-state="shown"
                >
                    <ul class="treelist">
                        <f:render
                            partial="AnalyzerTree"
                            arguments="{
                                type: type,
                                pageUid: pageUid,
                                tree: child
                            }"
                        />
                    </ul>
                </div>
            </f:if>
        </li>
    </f:for>
</f:if>

</html>
