#!/usr/bin/env php
<?php

declare(strict_types=1);

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

use App\Application\LiveComponents\ModalComponent;

echo "Testing ModalComponent Migration\n";
echo "==================================\n\n";

try {
    $modal = new ModalComponent(
        id: 'modal-test',
        initialData: []
    );

    echo "✓ ModalComponent created successfully\n";
    echo "  - ID: " . $modal->getId() . "\n\n";

    // Test open() method
    echo "Testing open() method...\n";
    $result = $modal->open('Test Modal', 'Test content', 'medium', []);
    echo "  ✓ open() returns array: " . (is_array($result) ? 'YES' : 'NO') . "\n";
    echo "  - Is open: " . ($result['is_open'] ? 'true' : 'false') . "\n";
    echo "  - Title: " . $result['title'] . "\n";
    echo "  - Size: " . $result['size'] . "\n\n";

    // Test close() method
    echo "Testing close() method...\n";
    $result = $modal->close();
    echo "  ✓ close() returns array: " . (is_array($result) ? 'YES' : 'NO') . "\n";
    echo "  - Is open: " . ($result['is_open'] ? 'true' : 'false') . "\n\n";

    // Test updateContent() method
    echo "Testing updateContent() method...\n";
    $result = $modal->updateContent('Updated content');
    echo "  ✓ updateContent() returns array: " . (is_array($result) ? 'YES' : 'NO') . "\n";
    echo "  - Content: " . $result['content'] . "\n\n";

    // Test changeSize() method
    echo "Testing changeSize() method...\n";
    $result = $modal->changeSize('large');
    echo "  ✓ changeSize() returns array: " . (is_array($result) ? 'YES' : 'NO') . "\n";
    echo "  - Size: " . $result['size'] . "\n\n";

    // Test confirm() method
    echo "Testing confirm() method...\n";
    $result = $modal->confirm('Confirm Action', 'Are you sure?');
    echo "  ✓ confirm() returns array: " . (is_array($result) ? 'YES' : 'NO') . "\n";
    echo "  - Is open: " . ($result['is_open'] ? 'true' : 'false') . "\n";
    echo "  - Title: " . $result['title'] . "\n";
    echo "  - Modal type: " . $result['modal_type'] . "\n";
    echo "  - Buttons: " . count($result['buttons']) . "\n\n";

    // Test alert() method
    echo "Testing alert() method...\n";
    $result = $modal->alert('Success', 'Operation completed', 'success');
    echo "  ✓ alert() returns array: " . (is_array($result) ? 'YES' : 'NO') . "\n";
    echo "  - Is open: " . ($result['is_open'] ? 'true' : 'false') . "\n";
    echo "  - Title: " . $result['title'] . "\n";
    echo "  - Modal type: " . $result['modal_type'] . "\n\n";

    echo "==================================\n";
    echo "✅ All ModalComponent tests passed!\n";

} catch (\Throwable $e) {
    echo "❌ Error: " . $e->getMessage() . "\n";
    echo "   File: " . $e->getFile() . ":" . $e->getLine() . "\n";
    exit(1);
}
