<?php
/**
 * @package   Essentials YOOtheme Pro 2.3.4 build 0217.0955
 * @author    ZOOlanders https://www.zoolanders.com
 * @copyright Copyright (C) Joolanders, SL
 * @license   http://www.gnu.org/licenses/gpl.html GNU/GPL
 */

namespace ZOOlanders\YOOessentials\Dynamic;

use YOOtheme\Builder;
use YOOtheme\Builder\BuilderConfig;
use YOOtheme\Builder\Source\SourceTransform;
use ZOOlanders\YOOessentials\UpdateTransform;

return [
    'config' => [
        BuilderConfig::class => __DIR__ . '/config/builder.json',
    ],

    'routes' => [
        ['post', GlobalQueryController::PRESAVE_QUERY_ENDPOINT, GlobalQueryController::class . '@presave']
    ],

    'events' => [
        'source.init' => [
            Listener\ExpandWordpressSources::class => ['@handle', -100],
        ],

        'source.type.metadata' => [
            Listener\ExpandSourcesMetadata::class => '@handle',
        ],

        'customizer.init' => [
            Listener\LoadCustomizerData::class => ['@handle', 10],
        ],

        'builder.type' => [
            Listener\ExtendBuilderType::class => ['@handle', -10],
        ],

        'yooessentials.config.load' => [
            Listener\ValidateGlobalQueries::class => ['@load'],
        ],
    ],

    'extend' => [
        Builder::class => function (Builder $builder, $app) {
            $sourceNode = $app(SourceNodeTransform::class);
            $sourceProps = $app(SourcePropsTransform::class);

            $builder->addTransform('preload', [$sourceNode, 'preload']); // before Source transform
            $builder->addTransform('prerender', [$sourceNode, 'prerender'], 2); // before Source transform

            $builder->addTransform('preload', [$sourceProps, 'preload']); // before Source transform
            $builder->addTransform('prerender', [$sourceProps, 'prerender'], 4); // after Source transforms
        },

        SourceTransform::class => function (SourceTransform $transform) {
            $transform->addFilter('time', [SourceFilter::class, 'applyTime'], -10);
            $transform->addFilter('datemodify', [SourceFilter::class, 'applyDatemodify'], -10);
        },

        SourceResolverManager::class => function (SourceResolverManager $manager, $app) {
            $manager->addResolver($app(Resolvers\ParentSourceResolver::class));
            $manager->addResolver($app(Resolvers\NodeSourceResolver::class));
            $manager->addResolver($app(Resolvers\ComposedSourceResolver::class));
            $manager->addResolver($app(Resolvers\GlobalSourceQueryResolver::class));
            $manager->addResolver($app(Resolvers\AdjacentSourceResolver::class));
            $manager->addResolver($app(Resolvers\SourceQueryArgumentsResolver::class));
            $manager->addResolver($app(Resolvers\SourceQueryResolver::class));
        },

        UpdateTransform::class => function (UpdateTransform $update) {
            $update->addGlobals(require __DIR__ . '/updates.php');
        },
    ],

    'services' => [
        SourceResolverManager::class => '',
    ],
];
