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

namespace ZOOlanders\YOOessentials\Access;

use ZOOlanders\YOOessentials\Builder\SourceResolver;

class SourceTransform
{
    public function __invoke(object $node, array &$params)
    {
        if (($params['context'] ?? '') !== 'render') {
            return;
        }

        if (!isset($node->props['yooessentials_access_conditions'])) {
            return;
        }

        if (!empty($params['source'])) {
            foreach ($node->props['yooessentials_access_conditions'] as $condition) {
                SourceResolver::resolvePropsQueries((array) ($condition->source->props ?? []), $node, $params);
                SourceResolver::resolvePropsQueries((array) ($condition->source_extended->props ?? []), $node, $params);
            }
        }
    }
}
