import { useState } from 'react'; import { sumFinancialAmounts } from '@/lib/financial-calculators'; type Row = { label: string; amount: string }; const initialRows = (): Row[] => [ 'Instalações', 'Equipamentos', 'Preparação e arranque', 'Fundo de maneio inicial', ].map((label) => ({ label, amount: '' })); export function restoreInitialBudget(snapshot: string): Row[] { try { const parsed = JSON.parse(snapshot); if ( parsed.version === 1 && Array.isArray(parsed.rows) && parsed.rows.length <= 30 && parsed.rows.every( (row: Row) => typeof row?.label === 'string' && row.label.length <= 120 && typeof row.amount === 'string' && row.amount.length <= 40, ) ) return parsed.rows; } catch { /* Preserve the saved original; no invented amounts. */ } return initialRows(); } export default function InvestmentInitialBudget({ snapshot, currency, onChange, }: { snapshot: string; currency: string; onChange: (key: string, value: string) => void; }) { const [rows, setRows] = useState(() => restoreInitialBudget(snapshot)); const [message, setMessage] = useState(''); const save = (next: Row[]) => { setRows(next); setMessage(''); onChange( 'initial_budget_snapshot', JSON.stringify({ version: 1, rows: next }), ); }; return (

Ajuda para construir o investimento inicial

Liste apenas os custos iniciais aplicáveis. O fundo de maneio cobre o arranque; não repita aqui custos já incluídos noutra parcela. Um valor desconhecido fica em branco, não é zero.

{rows.map((row, index) => (
))} {message &&

{message}

}
); }