import { useCallback } from 'react'; import { toast } from '@/components/ui/use-toast'; // 예산 데이터 리셋 훅 export const useBudgetReset = ( resetTransactions: () => void, resetCategoryBudgets: () => void, resetBudgetDataInternal: () => void ) => { // 모든 데이터 리셋 함수 const resetBudgetData = useCallback(() => { try { console.log('BudgetContext에서 데이터 리셋 시작'); // 데이터 초기화 순서 중요 resetTransactions(); resetCategoryBudgets(); resetBudgetDataInternal(); // 이벤트 발생 try { window.dispatchEvent(new Event('transactionUpdated')); window.dispatchEvent(new Event('budgetDataUpdated')); window.dispatchEvent(new Event('categoryBudgetsUpdated')); window.dispatchEvent(new StorageEvent('storage')); } catch (e) { console.error('이벤트 발생 오류:', e); } console.log('BudgetContext에서 데이터 리셋 완료'); // 토스트 알림 toast({ title: "모든 데이터 초기화", description: "예산과 지출 내역이 모두 초기화되었습니다.", }); return true; } catch (error) { console.error('데이터 초기화 중 오류:', error); toast({ title: "초기화 실패", description: "데이터를 초기화하는 중 오류가 발생했습니다.", variant: "destructive" }); return false; } }, [resetTransactions, resetCategoryBudgets, resetBudgetDataInternal]); return { resetBudgetData }; };