import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import '../../../common/extension/extension.dart'; import '../../../common/theme/theme.dart'; import '../../../domain/wallet/wallet.dart'; import '../../components/assets/assets.gen.dart'; /// Label & warna status order. Void/refund didahulukan (§4.5). (String, Color) orderStatusOf(CustomerOrder order) { if (order.isVoid) return ('Dibatalkan', AppColor.error); if (order.isRefund) return ('Direfund', AppColor.warning); return switch (order.status) { 'completed' => ('Selesai', AppColor.success), 'pending' => ('Menunggu', AppColor.warning), 'cancelled' => ('Dibatalkan', AppColor.error), _ => ('Diproses', AppColor.info), }; } String orderTypeLabel(String orderType) => switch (orderType) { 'dine_in' => 'Makan di tempat', 'take_away' || 'takeaway' => 'Bawa pulang', 'delivery' => 'Diantar', '' => '-', _ => orderType.replaceAll('_', ' '), }; AssetGenImage orderTypeIcon(CustomerOrder order) => order.isDineIn ? Assets.icons.dineIn : Assets.icons.takeaway; /// "30 Sep 2026, 19:01 WIB". String formatOrderTime(DateTime? time) { if (time == null) return '-'; return '${DateFormat('d MMM yyyy, HH:mm', 'id_ID').format(time.toWib)} WIB'; } /// Kuantitas item: "2 × Rp 25.000", atau "1 × 4,2 ons" untuk item timbangan. String formatItemQuantity(CustomerOrderItem item) { if (item.isWeighted) { final weight = NumberFormat('0.###', 'id_ID').format(item.weight); return '${item.quantity} × $weight ${item.unitName ?? ''}'.trim(); } return '${item.quantity} × ${item.unitPrice.currencyFormatRp}'; } class OrderStatusBadge extends StatelessWidget { const OrderStatusBadge({super.key, required this.order}); final CustomerOrder order; @override Widget build(BuildContext context) { final (label, color) = orderStatusOf(order); return Container( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4), decoration: BoxDecoration( color: color.withOpacity(0.1), borderRadius: BorderRadius.circular(999), ), child: Text( label, style: AppStyle.xs.copyWith(color: color, fontWeight: FontWeight.w700), ), ); } }