import { Ionicons } from "@expo/vector-icons";
import { router, useLocalSearchParams } from "expo-router";
import { Alert, Image, ScrollView, View } from "react-native";
import { Badge } from "@/components/ui/Badge";
import { Button } from "@/components/ui/Button";
import { Card, InfoRow, Section } from "@/components/ui/Card";
import { AppHeader } from "@/components/ui/Header";
import { Screen } from "@/components/ui/Screen";
import { Text } from "@/components/ui/Text";
import { getBranchById } from "@/lib/data/branches";
import { routes } from "@/lib/routes";
import { useOrdersStore } from "@/lib/stores/ordersStore";
import { colors, gutter, radii } from "@/lib/theme";
import { formatETB } from "@/lib/utils";
const toneFor = {
requested: "neutral",
confirmed: "info",
paid: "brand",
dispatched: "warn",
delivered: "brand",
completed: "brand",
cancelled: "danger",
} as const;
export default function OrderDetailScreen() {
const { id } = useLocalSearchParams<{ id: string }>();
const order = useOrdersStore((s) => s.getById(id));
const cancelOrder = useOrdersStore((s) => s.cancelOrder);
const updateStatus = useOrdersStore((s) => s.updateStatus);
if (!order) {
return (
Order not found.
);
}
const branch = order.branchId ? getBranchById(order.branchId) : undefined;
const canCancel = !["delivered", "completed", "cancelled"].includes(order.status);
return (
}
/>
{order.id}
{order.fulfillment === "pickup" ? "Pickup order" : "Delivery order"}
{order.customerName} · {order.customerPhone}
{order.notes ? (
Notes: {order.notes}
) : null}
{order.items.map((item, index) => (
{item.name}
{item.unit} · Qty {item.quantity}
{item.requiresPrescription ? " · RX" : ""}
{formatETB(item.price * item.quantity)}
))}
{order.addressLine ? (
) : null}
{branch ? (
) : (
)}
{(order.discount ?? 0) > 0 ? (
) : null}
{(order.corporateCovered ?? 0) > 0 ? (
) : null}
{(order.timeline ?? []).map((step, index, arr) => (
{index < arr.length - 1 ? (
) : null}
{step.label}
{new Date(step.at).toLocaleString()}
))}
{order.status !== "cancelled" && order.status !== "delivered" ? (
);
}