<?php
/**
 * Auto Update All Pages - FAST!
 */

echo "⚡ تحديث سريع.../n";

// Get all PHP files in public folder
$files = glob('../public/*.php');

foreach ($files as $file) {
    $content = file_get_contents($file);
    $updated = false;
    
    // Add CSS if not exists
    if (strpos($content, 'product-cards.css') === false && strpos($content, '</head>') !== false) {
        $content = str_replace('</head>', '    <link rel="stylesheet" href="../assets/css/product-cards.css">' . "/n</head>", $content);
        $updated = true;
    }
    
    // Add component include after session_start
    if (strpos($content, 'product-card.php') === false && strpos($content, 'session_start()') !== false) {
        $content = str_replace('session_start();', "session_start();\nrequire_once '../includes/product-card.php';", $content);
        $updated = true;
    }
    
    if ($updated) {
        file_put_contents($file, $content);
        echo "✅ " . basename($file) . "/n";
    }
}

echo "/n🎉 تم!/n";
