import { create } from 'zustand';

interface FileBrowserStore {
  viewMode: 'grid' | 'list';
  currentFolder: string;
  selectedFiles: string[];
  setViewMode: (mode: 'grid' | 'list') => void;
  setCurrentFolder: (folder: string) => void;
  toggleFileSelection: (fileId: string) => void;
  clearSelection: () => void;
}

export const useFileBrowserStore = create<FileBrowserStore>((set) => ({
  viewMode: 'grid',
  currentFolder: '',
  selectedFiles: [],
  setViewMode: (mode) => set({ viewMode: mode }),
  setCurrentFolder: (folder) => set({ currentFolder: folder, selectedFiles: [] }),
  toggleFileSelection: (fileId) =>
    set((state) => ({
      selectedFiles: state.selectedFiles.includes(fileId)
        ? state.selectedFiles.filter((id) => id !== fileId)
        : [...state.selectedFiles, fileId],
    })),
  clearSelection: () => set({ selectedFiles: [] }),
}));
