<?php
// test-date8.php - تست نهایی

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

echo "<h2>🧪 تست نهایی jalaliDate()</h2>";

// ===== تست 1: تاریخ‌های مشخص =====
echo "<h3>📅 تست 1: تاریخ‌های مشخص</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',
    '2025-03-20' => '1404/01/01',
];

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 = jalaliDate($input);
    $status = ($result == $expected) ? '✅' : '❌';
    $color = ($result == $expected) ? 'green' : 'red';
    echo "<tr><td>$input</td><td style='color:$color;font-weight:bold;'>$result</td><td>$expected</td><td>$status</td></tr>";
}
echo "</table>";

// ===== تست 2: از دیتابیس =====
echo "<h3>📅 تست 2: از دیتابیس (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>jalaliDate()</th></tr>";
foreach ($users as $user) {
    $converted = jalaliDate($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>";
?>