import React, { useReducer } from 'react';
import { appMetadataReducer, AppMetadataReducerDispatchType, IAppMetadataState, initialAppMetadataState } from '../reducers/AppMetadataReducer';

export interface IAppMetadataStateContext {
    appMetadataState: IAppMetadataState;
}
const initialStateContext: IAppMetadataStateContext = {
    appMetadataState: initialAppMetadataState
};
const initalDispatchContext: AppMetadataReducerDispatchType = null;

export const AppMetadataStateContext = React.createContext(initialStateContext);
export const AppMetadataDispatchContext = React.createContext(initalDispatchContext);

export function AppMetadataContextProvider({ children }) {
  const [appMetadataState, dispatch] = useReducer(appMetadataReducer, initialAppMetadataState);
  return (
    <AppMetadataStateContext.Provider value={{appMetadataState}}>
      <AppMetadataDispatchContext.Provider value={dispatch}>{children}</AppMetadataDispatchContext.Provider>
    </AppMetadataStateContext.Provider>
  );
}
