<?php
declare(strict_types=1);

namespace ProudNerds\Block;

use ProudNerds\Block\Block;
use Timber\{Post, Timber};

final class ContextBuilder
{


    public function __construct()
    {

    }

    public function build(Block $block, Post $post, array $variables = []): Context
    {
        $context = new Context($block, $post, Timber::get_context());

        foreach ($variables as $key => $variable) {
            $context->set($key, $variable);
        }
        $fields = get_fields($context->get('meta')['id']) ?: [];

        foreach ($fields as $key => $field) {
            $context->set($key, $field);
        }
        $context->getBlock()->extendContext($context);
        return $context;
    }


}
