import { useState, useRef } from 'react' import { Plus } from 'lucide-react' import { CustomDatePicker } from '../shared/CustomDateTimePicker' import { normalizePastedAmount } from './BudgetPanel.helpers' interface AddItemRowProps { onAdd: (data: { name: string; total_price: number; persons: number | null; days: number | null; note: string | null; expense_date: string | null }) => void t: (key: string) => string } export default function AddItemRow({ onAdd, t }: AddItemRowProps) { const [name, setName] = useState('') const [price, setPrice] = useState('') const [persons, setPersons] = useState('') const [days, setDays] = useState('') const [note, setNote] = useState('') const [expenseDate, setExpenseDate] = useState('') const nameRef = useRef(null) const handleAdd = () => { if (!name.trim()) return onAdd({ name: name.trim(), total_price: Number.parseFloat(String(price).replace(',', '.')) || 0, persons: Number.parseInt(persons) || null, days: Number.parseInt(days) || null, note: note.trim() || null, expense_date: expenseDate || null }) setName(''); setPrice(''); setPersons(''); setDays(''); setNote(''); setExpenseDate('') setTimeout(() => nameRef.current?.focus(), 50) } const inp = { border: '1px solid var(--border-primary)', borderRadius: 4, padding: '4px 6px', fontSize: 'calc(13px * var(--fs-scale-body, 1))', outline: 'none', fontFamily: 'inherit', width: '100%', background: 'var(--bg-input)', color: 'var(--text-primary)' } return ( setName(e.target.value)} onKeyDown={e => e.key === 'Enter' && handleAdd()} placeholder={t('budget.newEntry')} style={inp} /> setPrice(e.target.value)} onKeyDown={e => e.key === 'Enter' && handleAdd()} onPaste={e => { e.preventDefault(); setPrice(normalizePastedAmount(e.clipboardData.getData('text'))) }} placeholder="0,00" inputMode="decimal" style={{ ...inp, textAlign: 'center' }} /> setPersons(e.target.value)} onKeyDown={e => e.key === 'Enter' && handleAdd()} placeholder="-" inputMode="numeric" style={{ ...inp, textAlign: 'center', maxWidth: 60, margin: '0 auto' }} /> setDays(e.target.value)} onKeyDown={e => e.key === 'Enter' && handleAdd()} placeholder="-" inputMode="numeric" style={{ ...inp, textAlign: 'center', maxWidth: 60, margin: '0 auto' }} /> - - -
setNote(e.target.value)} onKeyDown={e => e.key === 'Enter' && handleAdd()} placeholder={t('budget.table.note')} style={inp} /> ) }