import { create } from 'zustand';
import { persist } from 'zustand/middleware';

interface CameraState {
  position: [number, number, number];
  target: [number, number, number];
}

interface ViewerState {
  locks: Record<string, boolean>;
  toggleLock: (moduleId: string) => void;
  cameras: Record<string, CameraState>;
  saveCamera: (moduleId: string, camera: CameraState) => void;
}

export const useViewerStore = create<ViewerState>()(
  persist(
    (set) => ({
      locks: {},
      toggleLock: (moduleId) => set((state) => ({ 
        locks: { ...state.locks, [moduleId]: !state.locks[moduleId] } 
      })),
      cameras: {},
      saveCamera: (moduleId, camera) => set((state) => ({
        cameras: { ...state.cameras, [moduleId]: camera }
      }))
    }),
    {
      name: 'brainwind-viewer-storage',
      partialize: (state) => ({ locks: state.locks, cameras: state.cameras }),
    }
  )
);
