
/**
 * 로컬 데이터 백업 만들기
 */
export const createLocalDataBackup = () => {
  const budgetDataBackup = localStorage.getItem('budgetData');
  const categoryBudgetsBackup = localStorage.getItem('categoryBudgets');
  const transactionsBackup = localStorage.getItem('transactions');
  
  console.log('로컬 데이터 백업:', {
    budgetData: budgetDataBackup ? '있음' : '없음',
    categoryBudgets: categoryBudgetsBackup ? '있음' : '없음',
    transactions: transactionsBackup ? '있음' : '없음'
  });
  
  return {
    budgetDataBackup,
    categoryBudgetsBackup,
    transactionsBackup
  };
};

/**
 * 로컬 데이터 복원하기
 */
export const restoreLocalDataBackup = (backup: {
  budgetDataBackup: string | null,
  categoryBudgetsBackup: string | null,
  transactionsBackup: string | null
}) => {
  const { budgetDataBackup, categoryBudgetsBackup, transactionsBackup } = backup;
  
  console.log('로컬 데이터 복원 시도');
  
  // 오류 발생 시 백업 데이터 복원
  if (budgetDataBackup) {
    localStorage.setItem('budgetData', budgetDataBackup);
  }
  if (categoryBudgetsBackup) {
    localStorage.setItem('categoryBudgets', categoryBudgetsBackup);
  }
  if (transactionsBackup) {
    localStorage.setItem('transactions', transactionsBackup);
  }
  
  // 이벤트 발생시켜 UI 업데이트
  window.dispatchEvent(new Event('budgetDataUpdated'));
  window.dispatchEvent(new Event('categoryBudgetsUpdated'));
  window.dispatchEvent(new Event('transactionUpdated'));
  
  console.log('로컬 데이터 복원 완료');
};
