import { View, Text, Image, TouchableOpacity, StyleSheet } from 'react-native'
import React from 'react'
import { useNavigation } from '@react-navigation/native'
export default function ActiveOrder({ orders = [], navigation: propNavigation }) {
// Use provided navigation prop if available, otherwise get from hook
const navigation = propNavigation || useNavigation();
// Safe number formatting helper
const formatCurrency = (value) => {
if (value === undefined || value === null) return '0.00';
if (typeof value === 'number') return value.toFixed(2);
if (typeof value === 'string') {
const num = parseFloat(value);
return isNaN(num) ? '0.00' : num.toFixed(2);
}
return '0.00';
};
if (!orders || orders.length === 0) {
return (
No active orders found
);
}
return (
{orders.map((order, index) => {
// Each order can have multiple items
return (
Order #{order.id}
{new Date(order.created_at || order.date).toLocaleDateString()} |
Status: {order.status}
{order.items && order.items.map((item, itemIndex) => (
{item.product_name || item.product?.title || 'Product'}
Qty: {item.quantity}
${formatCurrency(item.price || item.subtotal)}
))}
Total: ${formatCurrency(order.total_price || order.total_amount)}
navigation.navigate('Track Order', { orderId: order.id })}
className={`bg-primary rounded-full px-4 py-2`}
>
Track Order
);
})}
);
}
const styles = {
itemImage: {
width: 90,
height: 90,
borderRadius: 10,
},
}