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

type CollaboratorViewContextType = {
  isCollaboratorView: boolean;
  setIsCollaboratorView: (isCollaboratorView: boolean) => void;
};

const CollaboratorViewContext = createContext<CollaboratorViewContextType>({
  isCollaboratorView: false,
  setIsCollaboratorView: () => null,
});

export const CollaboratorViewProvider = ({
  children,
}: {
  children: React.ReactNode;
}) => {
  const [isCollaboratorView, setIsCollaboratorView] = useState(true);
  return (
    <CollaboratorViewContext.Provider
      value={{ isCollaboratorView, setIsCollaboratorView }}
    >
      {children}
    </CollaboratorViewContext.Provider>
  );
};

export const useCollaboratorView = () => {
  const context = useContext(CollaboratorViewContext);
  if (!context) {
    throw new Error(
      'useCollaboratorView must be used within a CollaboratorViewProvider',
    );
  }
  return context;
};
