import React, { useReducer } from 'react';
import { createCaseReducer, CreateCaseReducerDispatchType, ICreateCaseState, initialCreateCaseState } from '../reducers/CreateCaseReducer';

export interface ICreateCaseStateContext {
    createCaseState: ICreateCaseState;
}
const initialStateContext: ICreateCaseStateContext = {
    createCaseState: initialCreateCaseState
};
const initalDispatchContext: CreateCaseReducerDispatchType = null;

export const CreateCaseStateContext = React.createContext(initialStateContext);
export const CreateCaseDispatchContext = React.createContext(initalDispatchContext);

export function CreateCaseContextProvider({ children }) {
  const [createCaseState, dispatch] = useReducer(createCaseReducer, initialCreateCaseState);
  return (
    <CreateCaseStateContext.Provider value={{createCaseState}}>
      <CreateCaseDispatchContext.Provider value={dispatch}>{children}</CreateCaseDispatchContext.Provider>
    </CreateCaseStateContext.Provider>
  );
}
