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 { useRouter } 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"; const dummyData = { id: "dummy-1", proformaNumber: "PF-001", customerName: "John Doe", customerEmail: "john@example.com", customerPhone: "+1234567890", amount: { value: 1000, currency: "USD" }, currency: "USD", issueDate: "2026-03-10T11:51:36.134Z", dueDate: "2026-03-10T11:51:36.134Z", description: "Dummy proforma", notes: "Test notes", taxAmount: { value: 100, currency: "USD" }, discountAmount: { value: 50, currency: "USD" }, pdfPath: "dummy.pdf", userId: "user-1", items: [ { id: "item-1", description: "Test item", quantity: 1, unitPrice: { value: 1000, currency: "USD" }, total: { value: 1000, currency: "USD" } } ], createdAt: "2026-03-10T11:51:36.134Z", updatedAt: "2026-03-10T11:51:36.134Z" }; export default function ProformaDetailScreen() { const nav = useSirouRouter(); const router = useRouter(); 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"); setProforma(dummyData); // Use dummy data for testing } 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 */} {/* Proforma Info Card */} Proforma Details Proforma Number {proforma.proformaNumber} Issued Date {new Date(proforma.issueDate).toLocaleDateString()} Due Date {new Date(proforma.dueDate).toLocaleDateString()} Currency {proforma.currency} {proforma.description && ( Description {proforma.description} )} {/* Customer Info Card */} Customer Information Name {proforma.customerName} 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 */} ); }