import { create } from 'zustand';

export enum ActiveMenu {
  Upload = 'upload',
  Resource = 'resource',
  Setting = 'setting',
  Statistic = 'statistic',
}
export const activeMenuList = [
  {
    label: '上传',
    value: ActiveMenu.Upload,
  },
  {
    label: '资源管理',
    value: ActiveMenu.Resource,
  },
  {
    label: '设置',
    value: ActiveMenu.Setting,
  },
  {
    label: '统计',
    value: ActiveMenu.Statistic,
  },
];

interface LayoutStore {
  layout: 'left' | 'right';
  setLayout: (layout: 'left' | 'right') => void;
  /**
   * 当前激活的菜单，默认是upload
   */
  activeMenu: ActiveMenu;
  setActiveMenu: (activeMenu: ActiveMenu) => void;
  open: boolean;
  setOpen: (open: boolean) => void;
  showLabel: boolean;
  setShowLabel: (showLabel: boolean) => void;
  init: () => void;
}

export const useLayoutStore = create<LayoutStore>((set) => ({
  layout: 'left',
  setLayout: (layout) => set({ layout }),
  activeMenu: ActiveMenu.Upload,
  setActiveMenu: (activeMenu) => set({ activeMenu }),
  open: false,
  setOpen: (open) => set({ open }),
  showLabel: true,
  setShowLabel: (showLabel) => {
    localStorage.setItem('showLabel', showLabel.toString());
    set({ showLabel });
  },
  init: () => {
    const showLabel = localStorage.getItem('showLabel');
    if (showLabel) {
      set({ showLabel: showLabel === 'true' });
    }
  },
}));
