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

export type AppLanguage = 'en' | 'fr';

interface LanguageState {
  language: AppLanguage;
  setLanguage: (lang: AppLanguage) => void;
}

export const useLanguageStore = create<LanguageState>()(
  persist(
    set => ({
      language: 'fr',
      setLanguage: lang => set({ language: lang }),
    }),
    {
      name: 'contexta-language',
      storage: createJSONStorage(() => AsyncStorage),
    },
  ),
);
