import React, { useState, useEffect } from "react"; import { View, ScrollView, Pressable, ActivityIndicator } from "react-native"; import { useSirouRouter } from "@sirou/react-native"; import { AppRoutes } from "@/lib/routes"; import { Stack, useLocalSearchParams } from "expo-router"; import { Text } from "@/components/ui/text"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { ArrowLeft, DraftingCompass, Clock, Send, ExternalLink, ChevronRight, CheckCircle2, } from "@/lib/icons"; import { ScreenWrapper } from "@/components/ScreenWrapper"; import { StandardHeader } from "@/components/StandardHeader"; import { api } from "@/lib/api"; import { toast } from "@/lib/toast-store"; export default function ProformaDetailScreen() { const nav = useSirouRouter(); const { id } = useLocalSearchParams(); const [loading, setLoading] = useState(true); const [proforma, setProforma] = useState(null); useEffect(() => { fetchProforma(); }, [id]); const fetchProforma = async () => { try { setLoading(true); const data = await api.proforma.getById({ params: { id: id as string } }); setProforma(data); } catch (error: any) { console.error("[ProformaDetail] Error:", error); toast.error("Error", "Failed to load proforma details"); } finally { setLoading(false); } }; if (loading) { return ( ); } if (!proforma) { return ( Proforma not found ); } const subtotal = proforma.items?.reduce( (acc: number, item: any) => acc + (Number(item.total) || 0), 0, ) || 0; return ( {/* Header */} {/* Blue Summary Card */} ACTIVE Customer: {proforma.customerName} {proforma.description || "Proforma Request"} Due {new Date(proforma.dueDate).toLocaleDateString()} {proforma.proformaNumber} {/* Customer Info Strip (Added for functionality while keeping style) */} Email {proforma.customerEmail || "N/A"} Phone {proforma.customerPhone || "N/A"} {/* Line Items Card */} Line Items {proforma.items?.map((item: any, i: number) => ( {item.description} {item.quantity} × {proforma.currency}{" "} {Number(item.unitPrice).toLocaleString()} {proforma.currency} {Number(item.total).toLocaleString()} ))} Subtotal {proforma.currency} {subtotal.toLocaleString()} {Number(proforma.taxAmount) > 0 && ( Tax {proforma.currency}{" "} {Number(proforma.taxAmount).toLocaleString()} )} {Number(proforma.discountAmount) > 0 && ( Discount -{proforma.currency}{" "} {Number(proforma.discountAmount).toLocaleString()} )} Total Amount {proforma.currency} {Number(proforma.amount).toLocaleString()} {/* Notes Section (New) */} {proforma.notes && ( Additional Notes {proforma.notes} )} {/* Actions */} ); }