import { create } from 'zustand';
import { fetchMenuConfig } from '../services/authApi';
import type { MenuConfigItem } from '../services/authApi';

interface MenuState {
  menuConfig: MenuConfigItem[];
  isLoaded: boolean;
  loadMenuConfig: () => Promise<void>;
  setMenuConfig: (config: MenuConfigItem[]) => void;
}

export const useMenuStore = create<MenuState>((set) => ({
  menuConfig: [],
  isLoaded: false,

  loadMenuConfig: async () => {
    try {
      const config = await fetchMenuConfig();
      set({ menuConfig: config, isLoaded: true });
    } catch {
      set({ isLoaded: true });
    }
  },

  setMenuConfig: (config: MenuConfigItem[]) => {
    set({ menuConfig: config });
  },
}));
