import React, { createContext, useContext, useState, ReactNode } from 'react';

interface ImageViewerContextType {
  isImageViewerOpen: boolean;
  setImageViewerOpen: (isOpen: boolean) => void;
}

const ImageViewerContext = createContext<ImageViewerContextType | undefined>(undefined);

export const ImageViewerProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
  const [isImageViewerOpen, setImageViewerOpen] = useState(false);

  return (
    <ImageViewerContext.Provider value={{ isImageViewerOpen, setImageViewerOpen }}>
      {children}
    </ImageViewerContext.Provider>
  );
};

export const useImageViewer = (): ImageViewerContextType => {
  const context = useContext(ImageViewerContext);
  if (context === undefined) {
    throw new Error('useImageViewer must be used within an ImageViewerProvider');
  }
  return context;
};
