const STORAGE_KEY = 'nexusTimerState';

export const StorageService = {
  getState() {
    const savedState = localStorage.getItem(STORAGE_KEY);
    if (savedState) {
      try {
        return JSON.parse(savedState);
      } catch (e) {
        console.error("Error parsing saved state from localStorage", e);
        localStorage.removeItem(STORAGE_KEY); // Clear corrupted data
        return null;
      }
    }
    return null;
  },
  saveState(state) {
    localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
  },
  clearState() {
    localStorage.removeItem(STORAGE_KEY);
  }
};