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

export type AppLanguage = "en" | "am";

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

export const useLanguageStore = create<LanguageState>()(
  persist(
    (set) => ({
      language: "en",
      setLanguage: (language) => set({ language }),
    }),
    {
      name: "app-language",
      storage: createJSONStorage(() => AsyncStorage),
    },
  ),
);
