import React, { useState } from "react";
import {
View,
ScrollView,
Pressable,
TextInput,
StyleSheet,
Platform,
} from "react-native";
import { Text } from "@/components/ui/text";
import { Button } from "@/components/ui/button";
import { ArrowLeft, Trash2, Send, Plus } from "@/lib/icons";
import { ScreenWrapper } from "@/components/ScreenWrapper";
import { router, Stack } from "expo-router";
import { useColorScheme } from "nativewind";
import { ShadowWrapper } from "@/components/ShadowWrapper";
type Item = { id: number; description: string; qty: string; price: string };
// All TextInput styles are native StyleSheet — NO className on TextInput
// NativeWind className on TextInput causes focus loop because it re-processes
// styles each render and resets the responder chain.
const S = StyleSheet.create({
input: {
height: 44,
paddingHorizontal: 12,
fontSize: 12,
fontWeight: "500",
borderRadius: 6,
borderWidth: 1,
},
inputCenter: {
height: 44,
paddingHorizontal: 12,
fontSize: 14,
fontWeight: "500",
borderRadius: 6,
borderWidth: 1,
textAlign: "center",
},
});
function useInputColors() {
const { colorScheme } = useColorScheme();
const dark = colorScheme === "dark";
return {
bg: dark ? "rgba(30,30,30,0.8)" : "rgba(241,245,249,0.2)",
border: dark ? "rgba(255,255,255,0.08)" : "rgba(203,213,225,0.6)",
text: dark ? "#f1f5f9" : "#0f172a",
placeholder: "rgba(100,116,139,0.45)",
};
}
function Field({
label,
value,
onChangeText,
placeholder,
numeric = false,
center = false,
flex,
}: {
label: string;
value: string;
onChangeText: (v: string) => void;
placeholder: string;
numeric?: boolean;
center?: boolean;
flex?: number;
}) {
const c = useInputColors();
return (
{label}
);
}
export default function CreateProformaScreen() {
const [company, setCompany] = useState("");
const [project, setProject] = useState("");
const [validity, setValidity] = useState("");
const [terms, setTerms] = useState("");
const [items, setItems] = useState- ([
{ id: 1, description: "", qty: "1", price: "" },
]);
const c = useInputColors();
const updateField = (id: number, field: keyof Item, value: string) =>
setItems((prev) =>
prev.map((item) => (item.id === id ? { ...item, [field]: value } : item)),
);
const addItem = () =>
setItems((prev) => [
...prev,
{ id: Date.now(), description: "", qty: "1", price: "" },
]);
const removeItem = (id: number) => {
if (items.length > 1)
setItems((prev) => prev.filter((item) => item.id !== id));
};
const total = items.reduce(
(sum, item) =>
sum + (parseFloat(item.qty) || 0) * (parseFloat(item.price) || 0),
0,
);
return (
router.back()}
className="h-10 w-10 rounded-[10px] bg-card items-center justify-center border border-border"
>
New Proforma
{/* Recipient */}
{/* Terms */}
{/* Items */}
Add Item
{items.map((item, index) => (
Item {index + 1}
{items.length > 1 && (
removeItem(item.id)} hitSlop={8}>
)}
Description
updateField(item.id, "description", v)}
autoCorrect={false}
autoCapitalize="none"
returnKeyType="next"
/>
Qty
updateField(item.id, "qty", v)}
returnKeyType="next"
/>
Unit Price ($)
updateField(item.id, "price", v)}
returnKeyType="done"
/>
Total
$
{(
(parseFloat(item.qty) || 0) *
(parseFloat(item.price) || 0)
).toFixed(2)}
))}
{/* Summary */}
Estimated Total
$
{total.toLocaleString("en-US", {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}
);
}
function Label({
children,
noMargin,
}: {
children: string;
noMargin?: boolean;
}) {
return (
{children}
);
}