<?php
require_once __DIR__ . '/../src/Helpers/ContentCleaner.php';

$j = json_decode(file_get_contents(__DIR__ . '/../data/articles.json'), 1);

// Test on a few articles
foreach ([0, 1, 5, 30, 80] as $idx) {
    $a = $j[$idx];
    echo "\n====== {$a['title']} ======\n";
    $cleaned = App\Helpers\ContentCleaner::clean($a['content']);
    echo substr($cleaned, 0, 600) . "\n...\n";
}

// Final image count
$allImgs = 0; $missing = 0; $broken = 0;
foreach ($j as $a) {
    $c = App\Helpers\ContentCleaner::clean($a['content']);
    preg_match_all('/<img[^>]+src="([^"]+)"/i', $c, $m);
    $allImgs += count($m[1]);
    foreach ($m[1] as $src) {
        if (strpos($src, '/cozummerkezi/https://') !== false) $broken++;
        if (strpos($src, '/cozummerkezi/assets/images/') !== false) {
            $f = basename($src);
            if (!file_exists(__DIR__ . '/../public/assets/images/' . $f)) $missing++;
        }
    }
}
echo "\n=== FINAL ===";
echo "\nTotal images: $allImgs";
echo "\nBroken URLs: $broken";
echo "\nMissing files: $missing\n";
