import { useState, useEffect, useCallback } from 'react' import { budgets, type Budget, type BudgetDetail } from '@/lib/api' export function useBudgets() { const [list, setList] = useState([]) const [current, setCurrent] = useState(null) const [loading, setLoading] = useState(true) const fetchList = useCallback(async () => { try { const data = await budgets.list() setList(data) } catch { setList([]) } finally { setLoading(false) } }, []) const selectBudget = useCallback(async (id: string) => { setLoading(true) try { const detail = await budgets.get(id) setCurrent(detail) } finally { setLoading(false) } }, []) useEffect(() => { fetchList() }, [fetchList]) return { list, current, loading, fetchList, selectBudget, setCurrent } }