<?php
// test-date9.php - تست Carbon

require_once 'vendor/autoload.php';
require_once 'config/database.php';
require_once 'includes/db.php';
require_once 'includes/carbon_date.php';

use Carbon\Carbon;

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

// ===== تست 1: تاریخ‌های مشخص =====
echo "<h3>📅 تست 1: تاریخ‌های مشخص</h3>";
$tests = [
    '2025-09-23',
    '2025-06-11',
    '2025-11-07',
    '2026-07-20',
    '2025-03-20',
];

echo "<table border='1' cellpadding='8' dir='rtl'>";
echo "<tr><th>ورودی (میلادی)</th><th>خروجی (شمسی)</th></tr>";
foreach ($tests as $test) {
    $result = carbonJalali($test);
    echo "<tr><td>$test</td><td><strong>$result</strong></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>carbonJalali()</th></tr>";
foreach ($users as $user) {
    $converted = carbonJalali($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>";
?>