<?php

declare(strict_types=1);

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

use App\Framework\View\DomWrapper;

echo "=== Test Self-Closing Tag Parsing ===\n\n";

// Test 1: Self-closing syntax
echo "Test 1: Self-closing syntax <x-counter />}\n";
$html1 = '<html><body><x-counter id="demo" /></body></html>';
$dom1 = DomWrapper::fromString($html1);
echo "Parsed as: " . $dom1->document->saveHTML() . "\n\n";

// Test 2: Explicit closing tag
echo "Test 2: Explicit closing tag <x-counter></x-counter>\n";
$html2 = '<html><body><x-counter id="demo"></x-counter></body></html>';
$dom2 = DomWrapper::fromString($html2);
echo "Parsed as: " . $dom2->document->saveHTML() . "\n\n";

// Test 3: Multiple self-closing tags
echo "Test 3: Multiple self-closing tags\n";
$html3 = '<html><body><p>Before</p><x-counter /><p>After</p></body></html>';
$dom3 = DomWrapper::fromString($html3);
echo "Parsed as: " . $dom3->document->saveHTML() . "\n\n";

// Test 4: Check if elements are actually siblings
echo "Test 4: Check element relationships\n";
$body = $dom3->document->body;
if ($body) {
    echo "Body children count: " . $body->childNodes->length . "\n";
    foreach ($body->childNodes as $i => $child) {
        if ($child instanceof \Dom\Element) {
            echo "  Child #{$i}: {$child->tagName}\n";
        }
    }
}
