import { Ionicons } from "@expo/vector-icons"; import { router, useLocalSearchParams } from "expo-router"; import { 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 { products } from "@/lib/data/products"; import { useCartStore } from "@/lib/stores/cartStore"; import { usePrescriptionStore } from "@/lib/stores/prescriptionStore"; import { colors, gutter, radii } from "@/lib/theme"; import { routes } from "@/lib/routes"; const statusTone = { submitted: "neutral", under_review: "warn", approved: "brand", queried: "info", rejected: "danger", filled: "brand", } as const; const lineTone = { ready: "brand", review: "warn", unavailable: "danger", } as const; export default function PrescriptionDetailScreen() { const { id } = useLocalSearchParams<{ id: string }>(); const rx = usePrescriptionStore((s) => s.prescriptions.find((p) => p.id === id)); const reminders = usePrescriptionStore((s) => s.reminders.filter((r) => r.prescriptionId === id) ); const markRefilled = usePrescriptionStore((s) => s.markRefilled); const updateRxStatus = usePrescriptionStore((s) => s.updateRxStatus); const addProduct = useCartStore((s) => s.addProduct); if (!rx) { return ( Prescription not found. ); } const dueIn = (() => { if (!rx.lastFilledAt) return null; const due = new Date(rx.lastFilledAt); due.setDate(due.getDate() + rx.daysSupply); return Math.ceil((due.getTime() - Date.now()) / (1000 * 60 * 60 * 24)); })(); return ( {rx.imageUris[0] ? ( ) : null} {rx.medicineName} For {rx.patientName} {dueIn !== null ? ( {dueIn <= 0 ? "Refill overdue" : `Refill in ${dueIn} days`} ) : ( Awaiting first fill )}
{rx.medicines.map((m, i) => ( {m.name} ))}
{rx.notes ? : null}
{reminders.length === 0 ? ( No reminders yet. Set times so we can nudge you — and escalate if a dose is missed. ) : ( reminders.map((r) => ( {r.medicineName} {r.times.join(" · ")} · {r.graceMinutes} min grace {r.escalateOnMiss ? " · escalate if missed" : ""} )) )}