<?php
// test-date5.php - تست روش ساده

require_once 'config/database.php';
require_once 'includes/db.php';
require_once 'includes/date_simple.php';

echo "<h2>🧪 تست simpleJalali</h2>";

// ===== تست مستقیم =====
echo "<h3>📅 تست مستقیم:</h3>";
$tests = [
    '2025-09-23' => '1404/07/01',
    '2025-06-11' => '1404/03/21',
    '2025-11-07' => '1404/08/16',
    '2026-07-20' => '1405/04/29',
];

echo "<table border='1' cellpadding='8' dir='rtl'>";
echo "<tr><th>ورودی</th><th>خروجی کتابخانه</th><th>خروجی مورد انتظار</th><th>وضعیت</th></tr>";
foreach ($tests as $input => $expected) {
    $result = simpleJalali($input);
    $status = ($result == $expected) ? '✅' : '❌';
    echo "<tr><td>$input</td><td><strong>$result</strong></td><td>$expected</td><td>$status</td></tr>";
}
echo "</table>";

// ===== تست از دیتابیس =====
echo "<h3>📅 تست از دیتابیس (last_login):</h3>";
$users = fetchAll("SELECT id, name, family, last_login FROM users WHERE last_login IS NOT NULL LIMIT 5");

echo "<table border='1' cellpadding='8' dir='rtl'>";
echo "<tr><th>نام</th><th>last_login</th><th>simpleJalali()</th></tr>";
foreach ($users as $user) {
    $converted = simpleJalali($user['last_login']);
    echo "<tr>";
    echo "<td>" . htmlspecialchars($user['name'] . ' ' . $user['family']) . "</td>";
    echo "<td>" . htmlspecialchars($user['last_login']) . "</td>";
    echo "<td><strong>" . $converted . "</strong></td>";
    echo "</tr>";
}
echo "</table>";
?>