<?php

require_once __DIR__ . /../../vendor/autoload.php;

use App\Application\LiveComponents\DynamicForm\DynamicFormComponent;
use App\Application\LiveComponents\DynamicForm\DynamicFormState;
use App\Framework\LiveComponents\ValueObjects\ComponentId;
use App\Framework\LiveComponents\ValueObjects\ComponentData;

// Test State creation with form data
$initialState = new DynamicFormState(
    currentStep: 1,
    totalSteps: 4,
    formData: [
        'first_name' => 'John',
        'last_name' => 'Doe'
    ],
    errors: [],
    submitted: false,
    submissionId: null
);

echo "Initial formData:\n";
print_r($initialState->formData);
echo "\n";

// Test updateField
$updatedState = $initialState->withUpdatedField('email', 'john@example.com');

echo "After adding email:\n";
print_r($updatedState->formData);
echo "\n";

// Test Component with initialData
$componentData = $updatedState->toComponentData();
$component = new DynamicFormComponent(
    id: ComponentId::fromString('dynamic-form:test'),
    initialData: $componentData
);

$renderData = $component->getRenderData();
echo "Render data form_first_name: " . ($renderData->data['form_first_name'] ?? 'NOT SET') . "\n";
echo "Render data form_last_name: " . ($renderData->data['form_last_name'] ?? 'NOT SET') . "\n";
echo "Render data form_email: " . ($renderData->data['form_email'] ?? 'NOT SET') . "\n";
