<?php

declare(strict_types=1);

namespace App\Application\Controllers\Test;

use App\Application\Components\CounterComponent;
use App\Framework\Attributes\Route;
use App\Framework\Http\Method;
use App\Framework\LiveComponents\ComponentRegistry;
use App\Framework\Meta\MetaData;
use App\Framework\Router\Result\ViewResult;

final readonly class LiveComponentTestController
{
    public function __construct(
        private ComponentRegistry $componentRegistry
    ) {
    }

    #[Route('/test/livecomponents', method: Method::GET)]
    public function index(): ViewResult
    {
        // Create Counter Component (no TemplateRenderer needed)
        // The component will be automatically rendered by PlaceholderReplacer
        $counter = new CounterComponent(
            id: ComponentRegistry::makeId('counter', 'demo'),
            initialData: ['count' => 0]
        );

        return new ViewResult(
            template: 'livecomponents',
            metaData: MetaData::create(
                title: 'LiveComponents Test Suite',
                description: 'Zero-Dependency Interactive Components Test'
            ),
            data: [
                'counter' => $counter,  // Direkt das Component-Objekt übergeben
                'counterId' => $counter->getId(),
            ]
        );
    }
}
