import { useState } from 'react' import { useTranslation } from 'react-i18next' import { Card, CardContent, CardHeader, CardTitle, CardFooter } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Spinner } from '@/components/ui/spinner' import { budgets as budgetsApi, type Budget, ApiError } from '@/lib/api' interface Props { existingBudgets: Budget[] onCreated: () => void onCancel: () => void } export function BudgetSetup({ existingBudgets: _existingBudgets, onCreated, onCancel }: Props) { const { t } = useTranslation() const [month, setMonth] = useState('') const [currency, setCurrency] = useState('EUR') const [saving, setSaving] = useState(false) const handleGenerate = async () => { setSaving(true) try { await budgetsApi.generate({ month, currency }) onCreated() } catch (err) { if (err instanceof ApiError && err.status === 409) { // Budget already exists for this month — navigate to it by refreshing the list onCreated() } else { throw err } } finally { setSaving(false) } } return ( {t('budget.generate')}
setMonth(e.target.value)} />
setCurrency(e.target.value)} />
) }