"use client"; import { Plus, Trash2 } from "lucide-react"; import * as React from "react"; import { motion, AnimatePresence } from "framer-motion"; import { Button } from "~/components/ui/button"; import { DatePicker } from "~/components/ui/date-picker"; import { Input } from "~/components/ui/input"; import { Label } from "~/components/ui/label"; import { NumberInput } from "~/components/ui/number-input"; import { cn } from "~/lib/utils"; interface InvoiceItem { id: string; date: Date; description: string; hours: number; rate: number; amount: number; } interface InvoiceLineItemsProps { items: InvoiceItem[]; onAddItem: () => void; onRemoveItem: (index: number) => void; onUpdateItem: ( index: number, field: string, value: string | number | Date, ) => void; className?: string; } interface LineItemRowProps { item: InvoiceItem; index: number; canRemove: boolean; onRemove: (index: number) => void; onUpdate: ( index: number, field: string, value: string | number | Date, ) => void; } const LineItemCard = React.forwardRef( ({ item, index, canRemove, onRemove, onUpdate }, ref) => { return ( ); }, ); LineItemCard.displayName = "LineItemCard"; function MobileLineItem({ item, index, canRemove, onRemove, onUpdate, }: LineItemRowProps) { return (
{/* Description */}
onUpdate(index, "description", e.target.value)} placeholder="Describe the work performed..." className="pl-3 text-sm" />
{/* Date */}
onUpdate(index, "date", date ?? new Date())} size="sm" inputClassName="h-9" />
{/* Hours and Rate in a row */}
onUpdate(index, "hours", value)} min={0} step={0.25} width="full" />
onUpdate(index, "rate", value)} min={0} step={1} prefix="$" width="full" className="font-mono" />
{/* Bottom section with controls, item name, and total */}
Item # {index + 1}
Total ${(item.hours * item.rate).toFixed(2)}
); } export function InvoiceLineItems({ items, onAddItem, onRemoveItem, onUpdateItem, className, }: InvoiceLineItemsProps) { const canRemoveItems = items.length > 1; return (
Date Description Hours Rate Amount
{items.map((item, index) => ( {/* Desktop/Tablet Card */} {/* Mobile Card */} ))}
{/* Add Item Button */}
); }