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

const CaptionRenderAreaContext = createContext(false);

/** Render area in which {@link TableCaption} is rendered */
export function CaptionRenderArea({ children }: PropsWithChildren<{}>) {
  return <CaptionRenderAreaContext.Provider value={true}>{children}</CaptionRenderAreaContext.Provider>;
}

/** Return `true` if current component is located inside {@link CaptionRenderArea} */
export function useIsCaptionRenderArea() {
  return useContext(CaptionRenderAreaContext);
}
