<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// بيانات الاتصال بقاعدة البيانات
$servername = "localhost";
$username = "u565109619_user21user";
$password = "Raw159ptu@@";
$dbname = "u565109619_appdata";

$conn = new mysqli($servername, $username, $password, $dbname);

// التحقق من الاتصال
if ($conn->connect_error) {
    die("⚠️ فشل الاتصال بقاعدة البيانات: " . $conn->connect_error);
}

// جلب أحدث معرف R_ID والحالة
$lastR = '';
$status = '';
$sql = "SELECT R_ID, status FROM transactions ORDER BY created_at DESC LIMIT 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
    $lastR = $row['R_ID'];
    $status = $row['status'];
} else {
    $lastR = "لا يوجد معرف متاح";
    $status = "غير متوفر";
}

$conn->close();
?>

<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>عرض آخر معرف</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css">
    <style>
        body {
            background-color: #f4f4f9;
            font-family: Arial, sans-serif;
        }
        .container {
            margin-top: 50px;
        }
        .header {
            text-align: center;
            margin-bottom: 20px;
        }
        .header h1 {
            font-size: 2rem;
            color: #444;
        }
        .form-control {
            margin-bottom: 20px;
        }
        .btn-custom {
            background-color: #28a745;
            color: #fff;
            font-weight: bold;
            border: none;
            border-radius: 5px;
            padding: 10px 20px;
        }
        .btn-custom:hover {
            background-color: #218838;
        }
        .nav-icons {
            display: flex;
            justify-content: space-between;
            margin-top: 30px;
        }
        .nav-icons a {
            color: #007bff;
            font-size: 1.3rem;
            text-decoration: none;
        }
        .nav-icons a:hover {
            color: #0056b3;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>عرض آخر معرف وحالته</h1>
        </div>
        <form id="updateForm">
            <label for="rNumber">معرف العملية:</label>
            <input type="text" id="rNumber" class="form-control" value="<?php echo $lastR; ?>" readonly>

            <label for="status">الحالة:</label>
            <input type="text" id="status" class="form-control" value="<?php echo ($status == "Completed" ? "نجاح" : ($status == "Cancelled" ? "فشل" : "غير متوفر")); ?>" readonly>
        </form>

        <div class="nav-icons">
            <a href="dashboard.html"><i class="fas fa-home"></i> الصفحة الرئيسية</a>
            <a href="create.html"><i class="fas fa-plus-circle"></i> إنشاء رابط دفع</a>
        </div>
    </div>
</body>
</html>
