import { create } from 'zustand';

interface UIState {
  isLoading: boolean;
  isSidebarOpen: boolean;
  toast: {
    open: boolean;
    message: string;
    severity: 'success' | 'error' | 'warning' | 'info';
  };
  setLoading: (isLoading: boolean) => void;
  toggleSidebar: () => void;
  showToast: (message: string, severity?: 'success' | 'error' | 'warning' | 'info') => void;
  hideToast: () => void;
}

export const useUIStore = create<UIState>((set) => ({
  isLoading: false,
  isSidebarOpen: false,
  toast: {
    open: false,
    message: '',
    severity: 'info',
  },
  setLoading: (isLoading) => set({ isLoading }),
  toggleSidebar: () => set((state) => ({ isSidebarOpen: !state.isSidebarOpen })),
  showToast: (message, severity = 'info') =>
    set({ toast: { open: true, message, severity } }),
  hideToast: () =>
    set((state) => ({ toast: { ...state.toast, open: false } })),
}));
