| 1 |
<?php |
| 2 |
/** |
| 3 |
* Pure helpers for Order Progress email templates (mirrors order-progress-variant-logic.ts). |
| 4 |
* |
| 5 |
* @package YayMail |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace YayMail\Utils; |
| 9 |
|
| 10 |
/** |
| 11 |
* Order Progress variant helpers. |
| 12 |
*/ |
| 13 |
class OrderProgressVariantHelpers { |
| 14 |
|
| 15 |
/** |
| 16 |
* Step-marker column presets (widths sum 100). Must stay in sync with order-progress-variant-logic.ts (STEP_MARKER_PRESETS). |
| 17 |
* |
| 18 |
* @return array Presets keyed by step count 1–5; each has 'widths' and 'aligns' lists. |
| 19 |
*/ |
| 20 |
public static function get_step_marker_presets() { |
| 21 |
return [ |
| 22 |
1 => [ |
| 23 |
'widths' => [ 100 ], |
| 24 |
'aligns' => [ 'center' ], |
| 25 |
], |
| 26 |
2 => [ |
| 27 |
'widths' => [ 50, 50 ], |
| 28 |
'aligns' => [ 'left', 'right' ], |
| 29 |
], |
| 30 |
3 => [ |
| 31 |
'widths' => [ 33, 34, 33 ], |
| 32 |
'aligns' => [ 'left', 'center', 'right' ], |
| 33 |
], |
| 34 |
4 => [ |
| 35 |
'widths' => [ 12, 25, 25, 12 ], |
| 36 |
'aligns' => [ 'left', 'center', 'center', 'right' ], |
| 37 |
], |
| 38 |
5 => [ |
| 39 |
'widths' => [ 9, 20, 20, 20, 9 ], |
| 40 |
'aligns' => [ 'left', 'center', 'center', 'center', 'right' ], |
| 41 |
], |
| 42 |
]; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Connector segment colors for filled-bar inner table (left bar, icon, right bar). |
| 47 |
* |
| 48 |
* @param int $index Step index (0-based). |
| 49 |
* @param int $active_index Active step index (0-based). |
| 50 |
* @param int $step_count Total steps. |
| 51 |
* @param string $active_color Connector active color. |
| 52 |
* @param string $inactive_color Connector inactive color. |
| 53 |
* @return array{left: string, right: string} |
| 54 |
*/ |
| 55 |
public static function get_connector_segment_colors( $index, $active_index, $step_count, $active_color, $inactive_color ) { |
| 56 |
$index = (int) $index; |
| 57 |
$active_index = (int) $active_index; |
| 58 |
$step_count = (int) $step_count; |
| 59 |
|
| 60 |
$left = ( 0 === $index ) |
| 61 |
? 'transparent' |
| 62 |
: ( $index <= $active_index ? $active_color : $inactive_color ); |
| 63 |
|
| 64 |
$right = ( $index === $step_count - 1 ) |
| 65 |
? 'transparent' |
| 66 |
: ( $index < $active_index ? $active_color : $inactive_color ); |
| 67 |
|
| 68 |
return [ |
| 69 |
'left' => $left, |
| 70 |
'right' => $right, |
| 71 |
]; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Choose displayed step image URL (same rules as step-marker / filled-bar TS). |
| 76 |
* |
| 77 |
* @param bool $is_step_active Whether step is active or completed. |
| 78 |
* @param string $active_url Active image URL. |
| 79 |
* @param string $inactive_url Inactive image URL. |
| 80 |
* @return string |
| 81 |
*/ |
| 82 |
public static function resolve_step_image_url( $is_step_active, $active_url, $inactive_url ) { |
| 83 |
$active_url = (string) $active_url; |
| 84 |
$inactive_url = (string) $inactive_url; |
| 85 |
$chosen = $is_step_active ? $active_url : $inactive_url; |
| 86 |
if ( '' !== $chosen ) { |
| 87 |
return $chosen; |
| 88 |
} |
| 89 |
return '' !== $active_url ? $active_url : $inactive_url; |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Filled-bar icon pill background: inactive steps always use #E2E6EE. |
| 94 |
* |
| 95 |
* @param bool $is_step_active Whether step is active or completed. |
| 96 |
* @param string $raw_image_bg_color Per-step image background (may be empty). |
| 97 |
* @param string $connector_active_color Fallback when active and no per-step color. |
| 98 |
* @return string |
| 99 |
*/ |
| 100 |
public static function resolve_filled_bar_icon_background( $is_step_active, $raw_image_bg_color, $connector_active_color ) { |
| 101 |
$raw_image_bg_color = (string) $raw_image_bg_color; |
| 102 |
if ( ! $is_step_active ) { |
| 103 |
return '#E2E6EE'; |
| 104 |
} |
| 105 |
return '' !== $raw_image_bg_color ? $raw_image_bg_color : $connector_active_color; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Filled-bar label text color (legacy label_color overrides per-step / global). |
| 110 |
* |
| 111 |
* @param string $legacy_label_color Legacy single label color override. |
| 112 |
* @param bool $is_step_active Whether label is for active step. |
| 113 |
* @param string $step_label_active_color Per-step active color. |
| 114 |
* @param string $step_label_inactive_color Per-step inactive color. |
| 115 |
* @param string $global_label_active_color Element default active label color. |
| 116 |
* @param string $global_label_inactive_color Element default inactive label color. |
| 117 |
* @return string |
| 118 |
*/ |
| 119 |
public static function resolve_filled_bar_label_color( |
| 120 |
$legacy_label_color, |
| 121 |
$is_step_active, |
| 122 |
$step_label_active_color, |
| 123 |
$step_label_inactive_color, |
| 124 |
$global_label_active_color, |
| 125 |
$global_label_inactive_color |
| 126 |
) { |
| 127 |
$legacy_label_color = (string) $legacy_label_color; |
| 128 |
if ( '' !== $legacy_label_color ) { |
| 129 |
return $legacy_label_color; |
| 130 |
} |
| 131 |
$step_label_active_color = (string) $step_label_active_color; |
| 132 |
$step_label_inactive_color = (string) $step_label_inactive_color; |
| 133 |
if ( $is_step_active ) { |
| 134 |
return '' !== $step_label_active_color ? $step_label_active_color : $global_label_active_color; |
| 135 |
} |
| 136 |
return '' !== $step_label_inactive_color ? $step_label_inactive_color : $global_label_inactive_color; |
| 137 |
} |
| 138 |
} |
| 139 |
|