import React, { createContext, useContext, useState, ReactNode } from 'react';

export type BackupRestoreStep = 'backup' | 'restore' | 'export' | 'import';

interface BackupRestoreContextType {
  currentStep: BackupRestoreStep;
  goToStep: (step: BackupRestoreStep) => void;
}

const BackupRestoreContext = createContext<BackupRestoreContextType | undefined>(undefined);

export const useBackupRestore = () => {
  const context = useContext(BackupRestoreContext);
  if (!context) {
    throw new Error('useBackupRestore must be used within BackupRestoreProvider');
  }
  return context;
};

export const BackupRestoreProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
  const [currentStep, setCurrentStep] = useState<BackupRestoreStep>('backup');

  const goToStep = (step: BackupRestoreStep) => {
    setCurrentStep(step);
  };

  return (
    <BackupRestoreContext.Provider value={{ currentStep, goToStep }}>
      {children}
    </BackupRestoreContext.Provider>
  );
};
