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

export const customFieldsFormContextContext =
  createContext<CustomFieldsFormState | null>(null);

export const CustomFieldsFormContextProvider =
  customFieldsFormContextContext.Provider;
export const CustomFieldsWidgetContextConsumer =
  customFieldsFormContextContext.Consumer;

export const useCustomFieldsFormContext = () => {
  const value = useContext(customFieldsFormContextContext);
  assertContextValue('CustomFieldsFormContextProvider', value);
  return value as CustomFieldsFormState;
};
