$limit, 'offset' => $offset, 'search' => $search, 'order' => $order, 'dir' => $dir, 'status' => $status, 'created_from' => $createdFrom, 'created_to' => $createdTo, ]); $rows = []; foreach ($result['rows'] as $row) { $status = (string) ($row['status'] ?? ''); $statusBadge = 'neutral'; if ($status === 'sent') { $statusBadge = 'success'; } elseif ($status === 'failed') { $statusBadge = 'danger'; } $rows[] = [ 'id' => $row['id'] ?? null, 'to_email' => $row['to_email'] ?? '', 'subject' => $row['subject'] ?? '', 'template' => $row['template'] ?? '', 'status' => $status, 'status_badge' => $statusBadge, 'status_label' => t(ucfirst($status)), 'created_at' => dt($row['created_at'] ?? ''), 'sent_at' => dt($row['sent_at'] ?? ''), ]; } Router::json([ 'data' => $rows, 'total' => $result['total'] ?? 0, ]);