<?php
require_once __DIR__ . '/../../connect.php';

$sql = "SELECT * FROM `passengers` ORDER BY `created_at` DESC LIMIT 5";
$stmt = $con->prepare($sql);
$stmt->execute();

if ($stmt->rowCount() > 0) {
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

    // فك التشفير للحقول الحساسة
    foreach ($rows as &$row) {
        $row['phone']           = $encryptionHelper->decryptData($row['phone']);
        $row['email']           = $encryptionHelper->decryptData($row['email']);
        $row['gender']          = $encryptionHelper->decryptData($row['gender']);
        $row['birthdate']       = $encryptionHelper->decryptData($row['birthdate']);
        $row['site']            = $encryptionHelper->decryptData($row['site']);
        $row['first_name']      = $encryptionHelper->decryptData($row['first_name']);
        $row['last_name']       = $encryptionHelper->decryptData($row['last_name']);
        $row['sosPhone']        = $encryptionHelper->decryptData($row['sosPhone']);
        $row['education']       = $encryptionHelper->decryptData($row['education']);
        $row['employmentType']  = $encryptionHelper->decryptData($row['employmentType']);
        $row['maritalStatus']   = $encryptionHelper->decryptData($row['maritalStatus']);
    }

    jsonSuccess($rows);
} else {
    jsonError("No passengers found");
}
?>