import React, { createContext, useContext } from 'react';
import type useWorkspaceSelection from './useWorkspaceSelection';

export type WorkspaceSelectionValue = ReturnType<typeof useWorkspaceSelection>;

const WorkspaceSelectionContext = createContext<WorkspaceSelectionValue | null>(null);

interface WorkspaceSelectionProviderProps {
  value: WorkspaceSelectionValue;
  children: React.ReactNode;
}

export const WorkspaceSelectionProvider: React.FC<WorkspaceSelectionProviderProps> = ({ value, children }) => (
  <WorkspaceSelectionContext.Provider value={value}>
    {children}
  </WorkspaceSelectionContext.Provider>
);

export const useWorkspaceSelectionContext = () => {
  const context = useContext(WorkspaceSelectionContext);
  if (!context) {
    throw new Error('useWorkspaceSelectionContext must be used within a WorkspaceSelectionProvider');
  }
  return context;
};

export default WorkspaceSelectionContext;
