import { Ionicons } from "@expo/vector-icons"; import { Pressable, StyleSheet, Text, View } from "react-native"; import { DateTimeField } from "@/components/ui/DateTimeField"; import { Input } from "@/components/ui/Input"; import { StepperInput } from "@/components/ui/StepperInput"; import { fonts, spacing } from "@/constants/theme"; import { useAppTheme } from "@/contexts/ThemeContext"; import { formatCurrency, formatDate } from "@/lib/format"; export type EditableLineItem = { id?: string; date: Date; description: string; hours: string; rate: string; }; type LineItemEditorProps = { item: EditableLineItem; currency: string; expanded: boolean; onToggle: () => void; onChange: (patch: Partial) => void; onRemove: () => void; }; export function LineItemEditor({ item, currency, expanded, onToggle, onChange, onRemove, }: LineItemEditorProps) { const { colors } = useAppTheme(); const hours = Number(item.hours) || 0; const rate = Number(item.rate) || 0; const amount = hours * rate; const borderStyle = { borderTopColor: colors.border }; if (!expanded) { return ( [styles.row, borderStyle, pressed && styles.rowPressed]} > {item.description.trim() || "Untitled line"} {formatDate(item.date)} · {hours}h × {formatCurrency(rate, currency)} {formatCurrency(amount, currency)} ); } return ( Line item onChange({ description })} placeholder="What was done" /> onChange({ hours })} placeholder="0" /> onChange({ rate })} keyboardType="decimal-pad" placeholder="0" /> onChange({ date })} /> {formatCurrency(amount, currency)} Remove ); } const styles = StyleSheet.create({ row: { flexDirection: "row", alignItems: "center", gap: spacing.sm, paddingVertical: spacing.sm, borderTopWidth: 1, }, rowPressed: { opacity: 0.9, }, rowMain: { flex: 1, gap: 2, }, rowTitle: { fontFamily: fonts.bodyMedium, fontSize: 15, }, rowSub: { fontFamily: fonts.body, fontSize: 12, }, rowAmount: { fontFamily: fonts.bodySemiBold, fontSize: 14, }, expanded: { gap: spacing.sm, paddingVertical: spacing.sm, borderTopWidth: 1, }, expandedHeader: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", }, expandedLabel: { fontFamily: fonts.bodySemiBold, fontSize: 13, textTransform: "uppercase", letterSpacing: 0.3, }, inlineRow: { flexDirection: "row", gap: spacing.md, }, inlineField: { flex: 1, }, expandedFooter: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", }, lineTotal: { fontFamily: fonts.bodySemiBold, fontSize: 16, }, removeButton: { flexDirection: "row", alignItems: "center", gap: 4, paddingVertical: spacing.xs, }, removeLabel: { fontFamily: fonts.bodyMedium, fontSize: 13, }, });