package com.example.ui.customer import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.data.model.Order import com.example.data.model.OrderStatus import com.example.ui.theme.FreshVegGreen import com.example.ui.theme.LoveRedPrimary import com.example.ui.theme.TextPrimary import com.example.ui.theme.TextSecondary import com.example.viewmodel.CustomerNavScreen import com.example.viewmodel.CustomerViewModel @OptIn(ExperimentalMaterial3Api::class) @Composable fun OrderTrackingScreen( orderId: String, customerViewModel: CustomerViewModel, onBack: () -> Unit, modifier: Modifier = Modifier ) { val orders by customerViewModel.allOrders.collectAsState() val order = orders.find { it.orderId == orderId } Scaffold( topBar = { TopAppBar( title = { Text("Track Order #${orderId.takeLast(4)}") }, navigationIcon = { IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") } } ) } ) { padding -> if (order == null) { Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Text("Order not found or loading...", color = TextSecondary) } } else { Column( modifier = modifier .fillMaxSize() .padding(padding) .padding(16.dp), verticalArrangement = Arrangement.spacedBy(24.dp) ) { Text( text = "Current Status: ${order.orderStatus.label}", fontSize = 18.sp, fontWeight = FontWeight.Bold, color = LoveRedPrimary ) OrderProgressStepper(currentStatus = order.orderStatus) } } } } @Composable fun OrderProgressStepper(currentStatus: OrderStatus) { val statuses = listOf( OrderStatus.PLACED, OrderStatus.PREPARING, OrderStatus.OUT_FOR_DELIVERY, OrderStatus.DELIVERED ) val currentIndex = statuses.indexOf(currentStatus) Column(verticalArrangement = Arrangement.spacedBy(16.dp)) { statuses.forEachIndexed { index, status -> val isActive = index <= currentIndex val isCurrent = index == currentIndex Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp) ) { Box( modifier = Modifier .size(24.dp) .clip(CircleShape) .background(if (isActive) FreshVegGreen else Color.LightGray), contentAlignment = Alignment.Center ) { if (isCurrent) { Box( modifier = Modifier .size(12.dp) .clip(CircleShape) .background(Color.White) ) } } Text( text = status.label, fontSize = 16.sp, fontWeight = if (isCurrent) FontWeight.Bold else FontWeight.Normal, color = if (isActive) TextPrimary else TextSecondary ) } } } }