'Pending', 'accepted' => 'Accepted', 'deliver_url' => 'Send URL', 'in_review' => 'In Review', 'modifications' => 'Changes Requested', 'completed' => 'Completed', 'cancelled' => 'Cancelled', 'rejected' => 'Rejected', ]; private const STATUS_STYLES = [ 'pending' => ['bg' => '#fef3c7', 'color' => '#92400e'], 'accepted' => ['bg' => '#dbeafe', 'color' => '#1e40af'], 'deliver_url' => ['bg' => '#ffedd5', 'color' => '#9a3412'], 'in_review' => ['bg' => '#e0e7ff', 'color' => '#3730a3'], 'modifications' => ['bg' => '#fce7f3', 'color' => '#9d174d'], 'completed' => ['bg' => '#d1fae5', 'color' => '#065f46'], 'cancelled' => ['bg' => '#fee2e2', 'color' => '#991b1b'], 'rejected' => ['bg' => '#fee2e2', 'color' => '#991b1b'], ]; private const ACTION_REQUIRED_STATUSES = ['pending', 'deliver_url', 'modifications']; private const IN_PROGRESS_STATUSES = ['accepted', 'in_review']; private const HISTORY_STATUSES = ['completed', 'cancelled', 'rejected']; public function __construct(array $view_data) { $this->view_data = $view_data; $this->categorizeOrders(); } /** * Categorize orders into the three tab groups. */ private function categorizeOrders(): void { $orders = $this->view_data['orders'] ?? []; foreach ($orders as $order) { $status = $this->extractField($order, 'status', 'pending'); if (in_array($status, self::ACTION_REQUIRED_STATUSES, true)) { $this->action_required[] = $order; } elseif (in_array($status, self::IN_PROGRESS_STATUSES, true)) { $this->in_progress[] = $order; } else { $this->history[] = $order; } } } public function render(): void { ?>
renderHeader(); ?> renderStaleWarning(); ?> renderTabs(); ?> renderPagination(); ?>

view_data['last_synced_at']) : ?> humanizeTimeDiff($this->view_data['last_synced_at'])) ); ?>
view_data['nonce_action'], $this->view_data['nonce_field']); ?>
view_data['stale'])) { return; } ?> action_required); $progress_count = count($this->in_progress); $history_count = count($this->history); ?>
renderActionRequiredTab(); ?>
renderInProgressTab(); ?>
renderHistoryTab(); ?>
action_required)) { ?>

action_required as $order) { $this->renderActionRequiredCard($order); } } private function renderActionRequiredCard($order): void { $order_id = $this->extractField($order, 'publisuites_order_id'); $status = $this->extractField($order, 'status', 'pending'); $type = $this->extractField($order, 'order_type'); $earnings = $this->extractField($order, 'earnings'); $deadline = $this->extractField($order, 'deadline_date'); $sale_date = $this->extractField($order, 'sale_date'); $website = $this->extractField($order, 'website'); $deadline_class = $this->getDeadlineUrgency($deadline); ?>
# renderTypeBadge($type); ?>
formatEarnings($earnings)); ?>
renderStatusBadge($status); ?>
formatDate($deadline)); ?>
formatDate($sale_date)); ?>
renderAcceptRejectForms($order_id); ?> renderSendUrlForm($order_id); ?>
renderDetailPanel($order, $order_id); ?>
in_progress)) { ?>

in_progress as $order) { $this->renderInProgressCard($order); } } private function renderInProgressCard($order): void { $order_id = $this->extractField($order, 'publisuites_order_id'); $status = $this->extractField($order, 'status', 'accepted'); $earnings = $this->extractField($order, 'earnings'); $deadline = $this->extractField($order, 'deadline_date'); $website = $this->extractField($order, 'website'); $deadline_class = $this->getDeadlineUrgency($deadline); ?>
# renderStatusBadge($status); ?>
formatEarnings($earnings)); ?>
formatDate($deadline)); ?>
renderDetailPanel($order, $order_id); ?>
history)) { ?>

history as $order) : ?> renderHistoryRow($order); ?>
extractField($order, 'publisuites_order_id'); $status = $this->extractField($order, 'status', 'completed'); $type = $this->extractField($order, 'order_type'); $sale_date = $this->extractField($order, 'sale_date'); $earnings = $this->extractField($order, 'earnings'); ?> # formatType($type)); ?> formatDate($sale_date)); ?> renderStatusBadge($status); ?> formatEarnings($earnings)); ?> formatType($type)); ?>
view_data['nonce_action'], $this->view_data['nonce_field']); ?>
view_data['nonce_action'], $this->view_data['nonce_field']); ?>
view_data['nonce_action'], $this->view_data['nonce_field']); ?>
extractField($order, 'suggested_title'); $order_details = $this->extractField($order, 'order_details'); $min_words = $this->extractField($order, 'min_words'); $social_media = $this->extractField($order, 'social_media'); $links = $this->extractField($order, 'links'); ?>
view_data['total'] ?? 0); $page = (int) ($this->view_data['page'] ?? 1); $page_size = (int) ($this->view_data['page_size'] ?? 10); if ($total <= $page_size) { return; } $total_pages = (int) ceil($total / $page_size); ?>
1) : ?> « »
$field) ? $order->$field : $default; } return $default; } /** * Convert an ISO 8601 timestamp to a human-readable "Xm ago" string. */ private function humanizeTimeDiff(string $isoTimestamp): string { try { $then = new DateTime($isoTimestamp); $now = new DateTime('now', $then->getTimezone()); $diff = $now->getTimestamp() - $then->getTimestamp(); if ($diff < 60) { return __('just now', '1platform-content-ai'); } if ($diff < 3600) { $minutes = (int) floor($diff / 60); /* translators: %d: number of minutes */ return sprintf(_n('%dm ago', '%dm ago', $minutes, '1platform-content-ai'), $minutes); } if ($diff < 86400) { $hours = (int) floor($diff / 3600); /* translators: %d: number of hours */ return sprintf(_n('%dh ago', '%dh ago', $hours, '1platform-content-ai'), $hours); } $days = (int) floor($diff / 86400); /* translators: %d: number of days */ return sprintf(_n('%dd ago', '%dd ago', $days, '1platform-content-ai'), $days); } catch (Exception $e) { return $isoTimestamp; } } /** * Format a date string for display. * * Supports d/m/y H:i, d/m/y, and ISO 8601 formats. */ private function formatDate(string $dateString): string { if (empty($dateString)) { return '—'; } $formats = [ 'd/m/y H:i', 'd/m/Y H:i', 'd/m/y', 'd/m/Y', ]; foreach ($formats as $format) { $date = DateTime::createFromFormat($format, $dateString); if ($date !== false) { return $date->format(get_option('date_format')); } } try { $date = new DateTime($dateString); return $date->format(get_option('date_format')); } catch (Exception $e) { return $dateString; } } /** * Get CSS class for deadline urgency. */ private function getDeadlineUrgency(string $deadline): string { if (empty($deadline)) { return ''; } $formats = [ 'd/m/y H:i', 'd/m/Y H:i', 'd/m/y', 'd/m/Y', ]; $deadlineDate = null; foreach ($formats as $format) { $parsed = DateTime::createFromFormat($format, $deadline); if ($parsed !== false) { $deadlineDate = $parsed; break; } } if ($deadlineDate === null) { try { $deadlineDate = new DateTime($deadline); } catch (Exception $e) { return ''; } } $now = new DateTime(); $diff = $deadlineDate->getTimestamp() - $now->getTimestamp(); if ($diff < 0) { return 'contai-ps-orders__deadline--overdue'; } if ($diff < 86400) { return 'contai-ps-orders__deadline--urgent'; } if ($diff < 172800) { return 'contai-ps-orders__deadline--warning'; } return ''; } /** * Format order type for display. */ private function formatType(string $type): string { $types = [ 'post' => __('Post', '1platform-content-ai'), 'link' => __('Link', '1platform-content-ai'), ]; return $types[strtolower($type)] ?? ucfirst($type); } /** * Format earnings for display. * * The API returns earnings as a string like "10 €", so return as-is or fallback. */ private function formatEarnings($amount): string { if (is_string($amount) && $amount !== '') { return $amount; } return '—'; } }