<?php
/**
 * Check Dompdf Installation
 */

echo "<h1>Dompdf Installation Check</h1>";

// Define base path
$base_path = __DIR__;
echo "<p><strong>Project root:</strong> " . $base_path . "</p>";

// Check if vendor folder exists
$vendor_path = $base_path . '/vendor';
if (file_exists($vendor_path)) {
    echo "<p style='color:green'>✅ vendor folder exists</p>";
    
    // List contents of vendor
    $vendor_contents = scandir($vendor_path);
    echo "<p>Vendor contents: " . implode(', ', array_diff($vendor_contents, ['.', '..'])) . "</p>";
    
    // Check if autoload.php exists
    $autoload_path = $vendor_path . '/autoload.php';
    if (file_exists($autoload_path)) {
        echo "<p style='color:green'>✅ autoload.php exists</p>";
        
        // Try to load it
        try {
            require_once $autoload_path;
            echo "<p style='color:green'>✅ autoload.php loaded successfully</p>";
            
            // Check if Dompdf class exists
            if (class_exists('Dompdf\Dompdf')) {
                echo "<p style='color:green'>✅ Dompdf class found</p>";
            } else {
                echo "<p style='color:red'>❌ Dompdf class not found</p>";
                
                // Check if dompdf folder exists
                $dompdf_path = $vendor_path . '/dompdf/dompdf';
                if (file_exists($dompdf_path)) {
                    echo "<p>✅ dompdf folder exists at: $dompdf_path</p>";
                } else {
                    echo "<p>❌ dompdf folder not found at: $dompdf_path</p>";
                }
            }
        } catch (Exception $e) {
            echo "<p style='color:red'>❌ Error loading autoload.php: " . $e->getMessage() . "</p>";
        }
    } else {
        echo "<p style='color:red'>❌ autoload.php not found at: $autoload_path</p>";
    }
} else {
    echo "<p style='color:red'>❌ vendor folder not found at: $vendor_path</p>";
}

// Check if composer.json exists
$composer_json = $base_path . '/composer.json';
if (file_exists($composer_json)) {
    echo "<p style='color:green'>✅ composer.json exists</p>";
    $composer_data = json_decode(file_get_contents($composer_json), true);
    echo "<pre>";
    print_r($composer_data);
    echo "</pre>";
} else {
    echo "<p style='color:red'>❌ composer.json not found</p>";
}

// Check if composer.lock exists
$composer_lock = $base_path . '/composer.lock';
if (file_exists($composer_lock)) {
    echo "<p style='color:green'>✅ composer.lock exists</p>";
} else {
    echo "<p style='color:orange'>⚠ composer.lock not found (this is okay)</p>";
}

echo "<hr>";
echo "<h2>Manual Installation Instructions</h2>";
echo "<p>If Dompdf is not installed, run these commands:</p>";
echo "<pre style='background:#f4f4f4; padding:10px;'>";
echo "cd " . $base_path . "\n";
echo "curl -sS https://getcomposer.org/installer | php\n";
echo "php composer.phar require dompdf/dompdf\n";
echo "</pre>";

echo "<p>Or if you have composer installed globally:</p>";
echo "<pre style='background:#f4f4f4; padding:10px;'>";
echo "cd " . $base_path . "\n";
echo "composer require dompdf/dompdf\n";
echo "</pre>";
?>