import { create } from 'zustand';
import AsyncStorage from '@react-native-async-storage/async-storage';

const ONBOARDING_KEY = 'onboarding_done';

const useAppStore = create((set) => ({
  onboardingDone: false,
  initialIdentity: '',
  appLoading: true,

  initApp: async () => {
    try {
      const value = await AsyncStorage.getItem(ONBOARDING_KEY);
      set({ onboardingDone: value === 'true', appLoading: false });
    } catch (_) {
      set({ onboardingDone: false, appLoading: false });
    }
  },

  setOnboardingDone: async () => {
    await AsyncStorage.setItem(ONBOARDING_KEY, 'true');
    set({ onboardingDone: true });
  },

  setInitialIdentity: (value) => set({ initialIdentity: value }),
}));

export default useAppStore;
