import { createContext, useContext } from 'react';
import { CustomFieldsWidgetState } from '../state';
import { assertContextValue } from '../createContext';

export const customFieldsWidgetContext =
  createContext<CustomFieldsWidgetState | null>(null);

export const CustomFieldsWidgetContextProvider =
  customFieldsWidgetContext.Provider;
export const CustomFieldsWidgetContextConsumer =
  customFieldsWidgetContext.Consumer;

export const useCustomFieldsWidgetContext = () => {
  const value = useContext(customFieldsWidgetContext);
  assertContextValue('CustomFieldsWidgetProvider', value);
  return value as CustomFieldsWidgetState;
};
