<?php
declare(strict_types=1);

namespace Celena\Core\Template\Tags;

use Celena\Core\Template\Engine;
use Celena\Core\Template\TagInterface;

/**
 * {include file="header.tpl"} — рендерит указанный шаблон с теми же переменными.
 */
final class IncludeTag implements TagInterface
{
    public function __construct(private readonly Engine $engine)
    {
    }

    public function render(array $params, array $vars, ?string $body = null): string
    {
        $file = trim((string) ($params['file'] ?? ''));
        if ($file === '') {
            return '';
        }
        return $this->engine->renderInclude($file, $vars);
    }
}
