# Development settings
[applicationContext == "Development"]
config {
    debug = 1
    no_cache = 1
    cache_period = 0
    fluid {
        templateCache = 0
        debug = 1
    }
}
[global]

# -----------------------------------------------
# PAGE configuration
# -----------------------------------------------
page = PAGE
page {
    # Define the document type
    typeNum = 0

    # Page title: "Page Title | Site Name"
    config {
        pageTitleFirst = 1
        pageTitleSeparator = |
        pageTitleSeparator.noTrimWrap = | | | 
    }

    # Viewport meta tag
    meta {
        viewport = width=device-width, initial-scale=1
    }

    # Favicon
    # shortcutIcon = EXT:zab_site/Resources/Public/Images/favicon.svg
    headerData.5 = TEXT
    headerData.5 {
        typolink {
            parameter.data = site:favicon
            returnLast = url
        }
        wrap = <link rel="icon" href="|" />
    }

    # Fluid Template configuration
    10 = FLUIDTEMPLATE
    10 {
        # Define the main HTML file (your page layout)
        file = EXT:zab_site/Resources/Private/Templates/Page/Default.html
        
        # Define the Layouts and Partials folder paths
        layoutRootPaths {
            10 = EXT:zab_site/Resources/Private/Layouts/
        }
        partialRootPaths {
            10 = EXT:zab_site/Resources/Private/Partials/
        }
        templateRootPaths {
            10 = EXT:zab_site/Resources/Private/Templates/Page/
        }
        
        # Define translation file paths
        languageRootPaths {
            10 = EXT:zab_site/Resources/Private/Language/
        }

        dataProcessing {
            # 10: SiteProcessor
            # 10 = TYPO3\CMS\Frontend\DataProcessing\SiteProcessor

            # 20: MenuProcessor (Navigation tree (level 1 and 2))
            20 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
            20 {
                levels = 2
                as = mainMenu
                expandAll = 1
                includeSpacer = 0
                titleField = title
            }

            # 35: Breadcrumb (rootline)
            35 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
            35 {
                special = rootline
                special.range = 0|-1
                includeNotInMenu = 1
                as = breadcrumb
            }

            # 40: LanguageMenuProcessor (auto-detects all site languages)
            40 = TYPO3\CMS\Frontend\DataProcessing\LanguageMenuProcessor
            40 {
                as = languageMenu
            }

            # 41: Add raw hreflang from site language config (no locale fallback)
            41 = Zab\ZabSite\DataProcessing\LanguageMenuRawHreflangProcessor
            41 {
                source = languageMenu
                targetField = hreflangRaw
            }

            # Footer partners (RecordType via Web > List)
            30 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
            30 {
                table = tx_zab_footer_partners
                pidInList.data = site:rootPageId
                recursive = 99
                orderBy = sorting
                as = FooterPartners

                dataProcessing {
                    10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
                    10 {
                        references.table = tx_zab_footer_partners
                        references.uid.field = uid
                        references.fieldName = zab_recordfooterpartners_logo
                        as = logo
                    }
                }
            }
        }

        # Global variables for use in HTML (e.g.: {siteName})
        variables {
            # the TYPO3_CONTEXT of TYPO3 (Development / Production / etc)
            applicationContext = TEXT
            applicationContext.data = applicationContext

            siteName = TEXT
            siteName.data = site:websiteTitle

            # Fetches the address with HTML tags
            siteAddress = TEXT
            siteAddress.data = site:address

            # Fetches the logo identifier from site configuration (e.g. t3://file?uid=3)
            # Resolved by Fluid's <f:image> ViewHelper in the template

            siteLogo = TEXT
            siteLogo.data = site:logo

            headerBarVisible = TEXT
            headerBarVisible.data = siteLanguage:header_bar_visible

            headerBarStartDate = TEXT
            headerBarStartDate.data = siteLanguage:header_bar_start_date

            headerBarEndDate = TEXT
            headerBarEndDate.data = siteLanguage:header_bar_end_date

            now = TEXT
            now.data = date:Y-m-d\TH:i:s\Z

            headerBarText = TEXT
            headerBarText.data = siteLanguage:header_bar_text

            headerLoginLink = TEXT
            headerLoginLink.data = siteLanguage:header_btn_link

            headerMostSearched = TEXT
            headerMostSearched.data = siteLanguage:header_most_searched
            headerMostSearched.replacement.10.search = /\r?\n/
            headerMostSearched.replacement.10.replace = |
            headerMostSearched.replacement.10.useRegExp = 1

            # to add Content Blocks
            content_main = CONTENT
            content_main {
                table = tt_content
                select {
                    # colPos = 0 This is the default "Main" column in TYPO3.
                    where = colPos=0
                    orderBy = sorting
                }
            }

            # Language Menu configuration (dynamic via DataProcessor)
            # languageMenu is now rendered via Fluid partial, see dataProcessing.40

            #CONTENT to create a custom footer menu with precise filtering
            footerMenu = CONTENT
            footerMenu {
                table = pages
                select {
                    pidInList.data = site:rootPageId
                    where = show_in_footer = 1 AND hidden = 0 AND deleted = 0
                    orderBy = sorting
                }

                renderObj = COA
                renderObj {
                    10 = TEXT
                    10 {
                        field = nav_title
                        ifEmpty.field = title
                        typolink {
                            parameter.field = uid
                            ATagParams = class="footer-link"
                        }
                        wrap = <li>|</li>
                    }
                }
            }
        }
    }
}

# -----------------------------------------------
# FAQs List: dataProcessing for zab/faqs-list
# -----------------------------------------------

# Disable page cache when FAQs filter/search/category params are present
[traverse(request.getQueryParams(), 'tx_zabfaqs') != '']
config.no_cache = 1
[global]

tt_content.zab_faqslist {
    dataProcessing {
        # Load all categories
        200 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
        200 {
            table = tx_zab_faqs_category
            pidInList.data = site:rootPageId
            recursive = 99
            orderBy = sorting
            as = faqsCategories
        }
        # Load ALL faqs items (unfiltered, unpaginated)
        210 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
        210 {
            table = tx_zab_faqs
            pidInList.data = site:rootPageId
            recursive = 99
            orderBy = sorting
            as = faqsItems
        }
        # Server-side filter + paginate (reads GET params tx_zabfaqs[page/category])
        300 = Zab\ZabSite\DataProcessing\FaqsListProcessor
        300 {
            # fallback if the content element field is 0/empty
            itemsPerPage = 24
            slidingWindowSize = 3
        }
        # Decorate only the current page's rows via ContentBlocks
        900 = Zab\ZabSite\DataProcessing\ContentBlockRecordsProcessor
        900 {
            variables = faqsItems,faqsCategories,faqsAllItems
        }
    }
}

# -----------------------------------------------
# Info-Hub List: dataProcessing for zab/info-hub-list
# -----------------------------------------------
tt_content.zab_infohublist {
    dataProcessing {
        200 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
        200 {
            table = tx_zab_info_hub_category
            pidInList.data = site:rootPageId
            recursive = 99
            orderBy = sorting
            as = infoHubCategories
        }
        210 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
        210 {
            table = tx_zab_info_hub
            pidInList.data = site:rootPageId
            recursive = 99
            orderBy = sorting
            as = infoHubItems
        }
        # Auto-resolve all ContentBlocks RecordType data
        900 = Zab\ZabSite\DataProcessing\ContentBlockRecordsProcessor
    }
}

# -----------------------------------------------
# Allow <iframe> in RTE content (CKEditor5 mediaEmbed)
# -----------------------------------------------
lib.parseFunc_RTE {
    allowTags := addToList(iframe)
    htmlSanitize = 0
}

# -----------------------------------------------
# Site title library
# -----------------------------------------------
lib.siteTitle = TEXT
lib.siteTitle {
    data = site:title
    
    # Fallback if the site title is still empty
    ifEmpty = Zab Site Project
    
    typolink {
        # Links the title to the root page of the current site
        parameter = site:rootPageId
        ATagParams = class="navbar-brand"
    }
}

# -----------------------------------------------
# ContentBlocks 
# -----------------------------------------------
lib.contentBlock {
    partialRootPaths {
        100 = EXT:zab_site/Resources/Private/Partials/
    }
}

# -----------------------------------------------
# Indexed Search
# -----------------------------------------------
config {
    index_enable = 1
    index_externals = 1
    index_metatags = 1
}

plugin.tx_indexedsearch {
    _LOCAL_LANG {
        de {
            displayResults.previous = Zurück
            displayResults.next = Weiter
            displayResults.page = Seite
            displayResults = <strong>%1$s bis %2$s</strong> von <strong>%3$s</strong> Ergebnissen
            result.noResult = Keine Ergebnisse gefunden.
            form.submit = Suchen
            form.searchFor = Suchen nach
        }
    }
    settings {
        displayAdvancedSearchLink = 1
        enableOpensearchPlugin = 0
        defaultOptions.searchType = 0
        defaultOptions.sortOrder = rank_flag
        blind.numberOfResults = 24
    }
    view {
        templateRootPaths {
            100 = EXT:zab_site/Resources/Private/Extensions/IndexedSearch/Templates/
        }
        partialRootPaths {
            100 = EXT:zab_site/Resources/Private/Extensions/IndexedSearch/Partials/
        }
        layoutRootPaths {
            100 = EXT:zab_site/Resources/Private/Extensions/IndexedSearch/Layouts/
        }
    }
}
