import React from 'react'; import { View, ScrollView, TouchableOpacity } from 'react-native'; import { MyText, tw, AppContainer } from 'common-ui'; import MaterialIcons from '@expo/vector-icons/MaterialIcons'; interface OrderProduct { productId: number; productName: string; quantity: number; price: number; unit: string; subtotal: number; } interface SnippetOrder { orderId: string; orderDate: string; customerName: string; totalAmount: string; slotInfo: { time: string; sequence: any[]; } | null; products: OrderProduct[]; matchedProducts: number[]; snippetCode: string; } interface SnippetOrdersViewProps { orders: SnippetOrder[]; snippetCode: string; onClose: () => void; } const OrderCard: React.FC<{ order: SnippetOrder; index: number }> = ({ order, index }) => { const orderDate = new Date(order.orderDate); const slotTime = order.slotInfo ? new Date(order.slotInfo.time) : null; return ( {/* Order Header */} {order.orderId} {order.customerName} ₹{order.totalAmount} {orderDate.toLocaleDateString()} {/* Slot Info */} {slotTime && ( Delivery: {slotTime.toLocaleString()} )} {/* Products */} Products: {order.products.map((product, index) => { const isMatched = order.matchedProducts.includes(product.productId); return ( {product.productName} {isMatched && ' ⭐'} {product.quantity} {product.unit} × ₹{product.price} ₹{product.subtotal.toFixed(2)} ); })} {/* Matched Products Summary */} Matched {order.matchedProducts.length} product(s) from snippet "{order.snippetCode}" ); }; const SnippetOrdersView: React.FC = ({ orders, snippetCode, onClose, }) => { const totalOrders = orders.length; const totalRevenue = orders.reduce((sum, order) => sum + parseFloat(order.totalAmount), 0); return ( {/* Header */} Orders for "{snippetCode}" {totalOrders} order{totalOrders !== 1 ? 's' : ''} • Total: ₹{totalRevenue.toFixed(2)} {/* Orders List */} {orders.length === 0 ? ( No matching orders No orders found that match this snippet's criteria ) : ( {orders.map((order, index) => ( {index < orders.length - 1 && ( )} ))} )} ); }; export default SnippetOrdersView;