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

// Compare a few articles to see what was lost
$titles_to_check = ['brmainte.exe', 'HP Laserjet 49 hatası', 'Epson Resetter', 'Yazıcıların ağa bağlanması'];

foreach ($j as $a) {
    if (!in_array($a['title'], $titles_to_check)) continue;
    
    // Find matching backup
    $orig = null;
    foreach ($backup as $b) {
        if ($b['title'] === $a['title']) { $orig = $b; break; }
    }
    if (!$orig) continue;
    
    echo "=== {$a['title']} ===\n";
    
    // Count text blocks
    preg_match_all('/<div class="article-text-block">(.*?)<\/div>/s', $a['content'], $textBlocks);
    preg_match_all('/<div class="article-image-block">(.*?)<\/div>/s', $a['content'], $imageBlocks);
    
    echo "Text blocks: " . count($textBlocks[1]) . "\n";
    echo "Image blocks: " . count($imageBlocks[1]) . "\n";
    
    // Show all text block content (first 200 chars each)
    foreach ($textBlocks[1] as $i => $tb) {
        $clean = trim(strip_tags($tb));
        echo "  Text[" . ($i+1) . "]: " . mb_substr($clean, 0, 150) . "\n";
    }
    
    // Show all image sources
    foreach ($imageBlocks[1] as $i => $ib) {
        preg_match('/src="([^"]+)"/', $ib, $m);
        echo "  Image[" . ($i+1) . "]: " . ($m[1] ?? 'no src') . "\n";
    }
    
    echo "\n";
}
