<?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\Source\Resolver;

use ZOOlanders\YOOessentials\Builder\SourceResolver;
use function YOOtheme\app;

trait HasDynamicArgs
{
    public static function resolveDynamicArguments($node, array $root = []): array
    {
        /** @var SourceResolver $sourceResolver */
        $sourceResolver = app(SourceResolver::class);
        $node = (object) $node;

        if (isset($node->source)) {
            $node->source = json_decode($node->source);
            $sourceResolver->resolveProps($node, $root);
        }

        return (array) ($node->props ?? ($node ?? []));
    }
}
