services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false
        bind:
            $extension: '@Zikula\ThemeModule\ZikulaThemeModule'
            $installed: '%env(ZIKULA_INSTALLED)%'
            Zikula\Bundle\CoreBundle\Site\SiteDefinitionInterface: '@zikula.site_definition'
            $mergerActive: '%zikula_asset_manager.combine%'

    Zikula\ThemeModule\:
        resource: '../../*'
        exclude: '../../{bootstrap.php,Tests,vendor}'

    Zikula\ThemeModule\Api\ApiInterface\PageAssetApiInterface: '@Zikula\ThemeModule\Api\PageAssetApi'

    Zikula\ThemeModule\Twig\Extension\PageVarExtension:
        arguments:
            $pageVars: '@zikula_core.common.theme.pagevars'

    zikula_core.common.theme.assets_js:
        class: Zikula\ThemeModule\Engine\AssetBag
    # public because AbstractExtension accesses this using container
    zikula_core.common.theme.assets_css:
        class: Zikula\ThemeModule\Engine\AssetBag
        public: true
    zikula_core.common.theme.assets_header:
        class: Zikula\ThemeModule\Engine\AssetBag
    zikula_core.common.theme.assets_footer:
        class: Zikula\ThemeModule\Engine\AssetBag

    Zikula\ThemeModule\Api\PageAssetApi:
        arguments:
          $styleSheets: '@zikula_core.common.theme.assets_css'
          $scripts: '@zikula_core.common.theme.assets_js'
          $headers: '@zikula_core.common.theme.assets_header'
          $footers: '@zikula_core.common.theme.assets_footer'

    zikula_core.common.theme.pagevars:
        class: Zikula\ThemeModule\Engine\ParameterBag

    Zikula\ThemeModule\Engine\AssetFilter:
        arguments:
          $headers: '@zikula_core.common.theme.assets_header'
          $footers: '@zikula_core.common.theme.assets_footer'
          $js: '@Zikula\ThemeModule\Engine\Asset\JsResolver'
          $css: '@Zikula\ThemeModule\Engine\Asset\CssResolver'
          $scriptPosition: '%script_position%'

    zikula_core.common.theme.themevars:
        class: Zikula\ThemeModule\Engine\ParameterBag
        public: true

    # public because AbstractExtension accesses this using container
    Zikula\ThemeModule\Engine\Asset:
        public: true

    Zikula\ThemeModule\Engine\Asset\Merger:
        arguments:
          $lifetime: '%zikula_asset_manager.lifetime%'
          $minify: '%zikula_asset_manager.minify%'
          $compress: '%zikula_asset_manager.compress%'
          $skipFiles:
            - '/jquery/jquery.min.js'
            - '%zikula.stylesheet.bootstrap.min.path%'
            - '%zikula.stylesheet.fontawesome.min.path%'
            - '/mmenu/css/mmenu.css'
            - '/mmenu/js/mmenu.js'

    Zikula\ThemeModule\Engine\Asset\JsResolver:
        arguments:
          $env: '%env(APP_ENV)%'
          $bag: '@zikula_core.common.theme.assets_js'
          $combine: '%zikula_asset_manager.combine%'

    Zikula\ThemeModule\Engine\Asset\CssResolver:
        arguments:
          $env: '%env(APP_ENV)%'
          $bag: '@zikula_core.common.theme.assets_css'
          $combine: '%zikula_asset_manager.combine%'

    # override TwigBundle's Twig\Environment definition with Zikula's own child class
    # see vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
    twig:
        class: Zikula\ThemeModule\Bridge\Twig\EventEnabledTwigEngine
        public: true
        arguments:
          $loader: '@twig.loader'
          $options: []
        calls:
          - setEventDispatcher: ['@event_dispatcher']
          - addGlobal: ['app', '@twig.app_variable']
          - addGlobal: ['pagevars', '@zikula_core.common.theme.pagevars']
          - addGlobal: ['themevars', '@zikula_core.common.theme.themevars']
          - addGlobal: ['currentUser', '@Zikula\UsersModule\Api\ApiInterface\CurrentUserApiInterface']
          - addRuntimeLoader: ['@twig.runtime_loader']
        configurator: ['@twig.configurator.environment', 'configure']
    Twig_Environment: '@twig'
    Twig\Environment: '@twig'

    Zikula\ThemeModule\EventListener\CreateThemedResponseListener:
        arguments:
            $debug: '%env(APP_DEBUG)%'
        tags:
            - { name: monolog.logger, channel: request }

    Zikula\ThemeModule\EventListener\DefaultPageAssetSetterListener:
        arguments:
          $jsAssetBag: '@zikula_core.common.theme.assets_js'
          $cssAssetBag: '@zikula_core.common.theme.assets_css'
          $bootstrapJavascriptPath: '%zikula.javascript.bootstrap.min.path%'
          $bootstrapStylesheetPath: "%zikula.stylesheet.bootstrap.min.path%"
          $fontAwesomePath: '%zikula.stylesheet.fontawesome.min.path%'
        tags:
            - { name: monolog.logger, channel: request }

    Zikula\ThemeModule\EventListener\DefaultPageVarSetterListener:
        arguments:
          $pageVars: '@zikula_core.common.theme.pagevars'
        tags:
            - { name: monolog.logger, channel: request }

    Zikula\ThemeModule\EventListener\ControllerAnnotationReaderListener:
        tags:
            - { name: monolog.logger, channel: request }

    Zikula\ThemeModule\EventListener\AddThemePathsToLoaderListener:
      arguments:
        $loader: '@twig.loader'

    Zikula\ThemeModule\EventListener\AddJSConfigListener:
        arguments:
          $footers: '@zikula_core.common.theme.assets_footer'
          $defaultSessionName: '%zikula.session.name%'

    Zikula\ThemeModule\EventListener\ExceptionListener:
        arguments:
            $debug: '%env(APP_DEBUG)%'
