<?php
require 'config.php';
require 'includes/db.php';

echo "--- Router Debug ---\n";
echo "CWD: " . getcwd() . "\n";
echo "DIR: " . __DIR__ . "\n";

$slug = $_GET['name'] ?? 'test';
echo "Checking slug: $slug\n";

$stmt = $pdo->prepare("SELECT u.id, u.landing_page, d.domain_name, d.status FROM user_domains d JOIN users u ON d.user_id = u.id WHERE d.domain_name = ?");
$stmt->execute([$slug]);
$row = $stmt->fetch();

if ($row) {
    echo "Found record:\n";
    print_r($row);
    $tmpl = $row['landing_page'];
    $path = __DIR__ . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $tmpl . '.php';
    echo "Expected path: $path\n";
    echo "Path exists: " . (file_exists($path) ? "YES" : "NO") . "\n";
} else {
    echo "No matching slug found in user_domains.\n";
}

echo "\n--- Available Templates ---\n";
foreach (glob("templates/*.php") as $filename) {
    echo "$filename\n";
}
?>

