<?php
$pdo = require 'config/database.php';

function calculateScore($title, $h1, $desc, $kw) {
    $score = 0;
    $kw = strtolower($kw);
    
    if (strlen($title) >= 40 && strlen($title) <= 65) $score += 25;
    if ($kw && strpos(strtolower($title), $kw) !== false) $score += 15;
    
    if (strlen($h1) > 0) {
        $score += 10;
        if ($kw && strpos(strtolower($h1), $kw) !== false) $score += 10;
    }
    
    if (strlen($desc) >= 100 && strlen($desc) <= 160) $score += 20;
    if ($kw && strpos(strtolower($desc), $kw) !== false) $score += 20;
    
    return $score;
}

$landings = $pdo->query("SELECT id, title, h1_title, description, focus_keyword FROM seo_landings LIMIT 5")->fetchAll();

foreach ($landings as $l) {
    $score = calculateScore($l['title'] ?? '', $l['h1_title'] ?? '', $l['description'] ?? '', $l['focus_keyword'] ?? '');
    echo "ID {$l['id']}: Score $score%\n";
    echo "  KW: {$l['focus_keyword']}\n";
    echo "  Title: {$l['title']} (" . strlen($l['title']) . ")\n";
    echo "  H1: {$l['h1_title']} (" . strlen($l['h1_title']) . ")\n";
    echo "  Desc: " . substr($l['description'], 0, 50) . "... (" . strlen($l['description']) . ")\n\n";
}
