<?php
include 'db_connection.php'; // تضمين الاتصال بقاعدة البيانات
include 'index.php'; // تضمين منطق جلب البيانات

// تحقق إذا كانت قيمة unique_id موجودة في GET
if (isset($_GET['unique_id'])) {
    $unique_id = $_GET['unique_id'];
    $result = fetchFormData($unique_id); // جلب البيانات من الدالة
} else {
    echo "No unique_id provided.";
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
</head>
<body>
    <div class="container mt-5">
        <div class="card">
            <div class="card-header">
                <h3 class="mb-0">Dashboard</h3>
            </div>
            <div class="card-body">
                <table class="table table-striped table-hover">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Name</th>
                            <th>Form Name</th>
                            <th>Created At</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        if (isset($result) && $result->num_rows > 0) {
                            while ($row = $result->fetch_assoc()) {
                                echo "<tr>";
                                echo "<td>" . $row['id'] . "</td>";
                                echo "<td>" . $row['name'] . "</td>";
                                echo "<td>" . $row['form_name'] . "</td>";
                                echo "<td>" . $row['created_at'] . "</td>";
                                echo "<td>
                                        <button class='btn btn-primary btn-sm' onclick='viewDetails(\"" . $row['unique_id'] . "\")'>View</button>
                                        <button class='btn btn-danger btn-sm' onclick='deleteEntry(" . $row['id'] . ")'>Delete</button>
                                      </td>";
                                echo "</tr>";
                            }
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
