import { create } from 'zustand';
export type HomeStore = {
  appKey: string;
  version: string;
  setAppKey: (appKey: string) => void;
  setVersion: (version: string) => void;
  filename: string;
  setFilename: (filename: string) => void;
  initApp: () => void;
  openUploadModal: boolean;
  setOpenUploadModal: (open: boolean) => void;
  text: string;
  setText: (text: string) => void;
  openSuccessModal: boolean;
  setOpenSuccessModal: (open: boolean) => void;
};
export const useHomeStore = create<HomeStore>((set) => ({
  appKey: '',
  version: '',
  setAppKey: (appKey: string) => {
    set({ appKey });
    localStorage.setItem('home-app-key', appKey);
  },
  setVersion: (version: string) => {
    set({ version });
    localStorage.setItem('home-app-version', version);
  },
  filename: '',
  setFilename: (filename: string) => {
    set({ filename });
    localStorage.setItem('home-file-name', filename);
  },
  initApp: () => {
    const appKey = localStorage.getItem('home-app-key') || '';
    const version = localStorage.getItem('home-app-version') || '';
    const filename = localStorage.getItem('home-file-name') || '';
    set({ appKey, version, filename });
  },
  openUploadModal: false,
  setOpenUploadModal: (open: boolean) => {
    set({ openUploadModal: open });
  },
  text: '',
  setText: (text: string) => {
    set({ text });
  },
  openSuccessModal: false,
  setOpenSuccessModal: (open: boolean) => {
    set({ openSuccessModal: open });
  },
}));
