import { Pressable, StyleSheet, Text, View } from "react-native"; import { DateTimeField } from "@/components/ui/DateTimeField"; import { Input } from "@/components/ui/Input"; import { SelectField } from "@/components/ui/SelectField"; import { fonts, spacing } from "@/constants/theme"; import { useAppTheme } from "@/contexts/ThemeContext"; import { defaultDueDate } from "@/lib/invoice-number"; type SelectOption = { label: string; value: string }; type InvoiceSetupFormProps = { businessId: string; onBusinessIdChange: (value: string) => void; businessOptions: SelectOption[]; businessError?: string; businessReadOnly?: boolean; clientId: string; onClientIdChange: (value: string) => void; clientOptions: SelectOption[]; clientError?: string; clientReadOnly?: boolean; invoiceNumber: string; onInvoiceNumberChange?: (value: string) => void; invoiceNumberReadOnly?: boolean; issueDate: Date; onIssueDateChange?: (date: Date) => void; issueDateReadOnly?: boolean; dueDate: Date; onDueDateChange: (date: Date) => void; taxRate: string; onTaxRateChange?: (value: string) => void; taxRateReadOnly?: boolean; notes: string; onNotesChange: (value: string) => void; sendReminderAt?: Date | null; onSendReminderAtChange?: (date: Date | null) => void; showSendReminder?: boolean; }; export function InvoiceSetupForm({ businessId, onBusinessIdChange, businessOptions, businessError, businessReadOnly = false, clientId, onClientIdChange, clientOptions, clientError, clientReadOnly = false, invoiceNumber, onInvoiceNumberChange, invoiceNumberReadOnly = false, issueDate, onIssueDateChange, issueDateReadOnly = false, dueDate, onDueDateChange, taxRate, onTaxRateChange, taxRateReadOnly = false, notes, onNotesChange, sendReminderAt, onSendReminderAtChange, showSendReminder = false, }: InvoiceSetupFormProps) { const { colors } = useAppTheme(); return ( {businessOptions.length === 0 ? ( Add a business in Entities before invoicing. ) : ( )} {clientOptions.length === 0 ? ( Add a client in Entities before invoicing. ) : ( )} {invoiceNumberReadOnly ? ( Invoice number {invoiceNumber} ) : ( )} {issueDateReadOnly ? ( Issue date {issueDate.toLocaleDateString()} ) : ( { onIssueDateChange?.(date); if (dueDate < date) onDueDateChange(defaultDueDate(date)); }} /> )} {taxRateReadOnly ? ( Tax rate {taxRate}% ) : ( )} {showSendReminder && onSendReminderAtChange ? ( <> {sendReminderAt ? ( onSendReminderAtChange(null)}> Clear send reminder ) : null} ) : null} ); } const styles = StyleSheet.create({ form: { gap: spacing.sm, }, hint: { fontFamily: fonts.body, fontSize: 14, lineHeight: 20, }, readOnlyField: { gap: 4, paddingVertical: 4, }, readOnlyLabel: { fontFamily: fonts.bodyMedium, fontSize: 13, }, readOnlyValue: { fontFamily: fonts.body, fontSize: 15, }, notesInput: { minHeight: 72, textAlignVertical: "top", }, clearReminder: { fontFamily: fonts.bodyMedium, fontSize: 13, marginBottom: spacing.xs, }, });