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

$limit = isset($_POST['limit']) ? (int)$_POST['limit'] : (isset($_GET['limit']) ? (int)$_GET['limit'] : 10);
$offset = isset($_POST['offset']) ? (int)$_POST['offset'] : (isset($_GET['offset']) ? (int)$_GET['offset'] : 0);

try {
    $sql = "SELECT id, first_name, last_name, phone FROM driver WHERE status <> 'active' ORDER BY id DESC LIMIT :limit OFFSET :offset";
    $stmt = $con->prepare($sql);
    $stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
    $stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
    $stmt->execute();
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

    // فك التشفير
    foreach ($rows as &$r) {
        $r['phone'] = $encryptionHelper->decryptData($r['phone']);
        $r['first_name']  = $encryptionHelper->decryptData($r['first_name']);
      	$r['last_name']  = $encryptionHelper->decryptData($r['last_name']);
    }

    jsonSuccess($rows); // يرجع كـ message: [...]
} catch (PDOException $e) {
    jsonError("Error: " . $e->getMessage());
}