fetch($countQuery, $params); $total = $totalResult['total']; $totalPages = ceil($total / $limit); // Obtener usuarios paginados $query = "SELECT u.id, u.phone_number, u.name, u.email, u.status, u.current_menu_id, u.current_step, u.created_at, u.updated_at, m.name as current_menu FROM users u LEFT JOIN menus m ON u.current_menu_id = m.id {$whereClause} ORDER BY u.created_at DESC LIMIT ? OFFSET ?"; $params[] = $limit; $params[] = $offset; $users = $db->fetchAll($query, $params); echo json_encode([ 'success' => true, 'data' => $users, 'pagination' => [ 'page' => $page, 'limit' => $limit, 'total' => $total, 'totalPages' => $totalPages, 'hasNext' => $page < $totalPages, 'hasPrev' => $page > 1 ] ]); } catch (Exception $e) { error_log("Error in get_users.php: " . $e->getMessage()); http_response_code(500); echo json_encode([ 'success' => false, 'error' => 'Error interno del servidor' ]); } ?>