<?php
$current = json_decode(file_get_contents(__DIR__ . '/../data/articles.json'), 1);
$backup = json_decode(file_get_contents(__DIR__ . '/../data/articles_backup_before_relayout.json'), 1);

$targets = ['brmainte.exe', 'HP Laserjet 49 hatasi', 'Epson Resetter', 'Yazicilarin aga baglanmasi'];

foreach ($backup as $b) {
    $titleClean = str_replace(['ı','ğ','ü','ş','ö','ç','İ','Ğ','Ü','Ş','Ö','Ç'], ['i','g','u','s','o','c','I','G','U','S','O','C'], $b['title']);
    $found = false;
    foreach ($targets as $t) {
        if (stripos($titleClean, str_replace(['ı','ğ','ü','ş','ö','ç','İ','Ğ','Ü','Ş','Ö','Ç'], ['i','g','u','s','o','c','I','G','U','S','O','C'], $t)) !== false) {
            $found = true; break;
        }
    }
    if (!$found) continue;
    
    // Find current version
    $cur = null;
    foreach ($current as $c) {
        if ($c['id'] === $b['id']) { $cur = $c; break; }
    }
    if (!$cur) continue;
    
    echo "=== {$b['title']} ===\n";
    
    // Extract all text content from backup (original)
    preg_match_all('/<div id="wb_Text\d+"[^>]*>(.*?)<\/div>/s', $b['content'], $origTexts);
    echo "Original text blocks: " . count($origTexts[1]) . "\n";
    foreach ($origTexts[1] as $i => $t) {
        $clean = trim(strip_tags($t));
        echo "  Orig[$i]: " . mb_substr($clean, 0, 120) . "\n";
    }
    
    // Extract text from current (clean layout)
    preg_match_all('/<div class="article-text-block">(.*?)<\/div>/s', $cur['content'], $curTexts);
    echo "Current text blocks: " . count($curTexts[1]) . "\n";
    foreach ($curTexts[1] as $i => $t) {
        $clean = trim(strip_tags($t));
        echo "  Curr[$i]: " . mb_substr($clean, 0, 120) . "\n";
    }
    
    echo "\n";
}
