import { View } from 'react-native'; import { tw, MyText } from 'common-ui'; const STAGES = ['Placed', 'Packed', 'Delivered'] as const; export type OrderStage = (typeof STAGES)[number]; /** * Maps a backend deliveryStatus to the furthest stage reached: * pending / processing -> 0 (Placed) * packaged -> 1 (Packed) * success / delivered -> 2 (Delivered) * Anything else (incl. cancelled) falls back to 0. */ export function deliveryStageIndex(deliveryStatus?: string | null): number { switch ((deliveryStatus || '').toLowerCase()) { case 'packaged': return 1; case 'success': case 'delivered': return 2; default: return 0; } } interface OrderStatusTrackerProps { deliveryStatus?: string | null; activeColor?: string; inactiveColor?: string; } export default function OrderStatusTracker({ deliveryStatus, activeColor = '#10B981', inactiveColor = '#E2E8F0', }: OrderStatusTrackerProps) { const cancelled = (deliveryStatus || '').toLowerCase() === 'cancelled'; const currentIndex = cancelled ? -1 : deliveryStageIndex(deliveryStatus); return ( {STAGES.map((label, i) => { const reached = i <= currentIndex; const dotColor = reached ? activeColor : inactiveColor; const leftLine = i > 0 && i <= currentIndex ? activeColor : inactiveColor; const rightLine = i < STAGES.length - 1 && i < currentIndex ? activeColor : inactiveColor; return ( {label} ); })} ); }