import React, { useReducer } from 'react';
import { initialRecommendationsState, IRecommendationsState, recommandationsReducer, RecommendationsReducerDispatchType } from '../reducers/RecommendationsReducer';

export interface IRecommendationStateContext {
    recommendationState: IRecommendationsState;
}
const initialStateContext: IRecommendationStateContext = {
    recommendationState: initialRecommendationsState
};
const initialDispatchContext: RecommendationsReducerDispatchType = null;

export const RecommendationStateContext = React.createContext(initialStateContext);
export const RecommendationDispatchContext = React.createContext(initialDispatchContext);

export function RecommendationContextProvider({ children }) {
  const [recommendationState, dispatch] = useReducer(recommandationsReducer, initialRecommendationsState);
  return (
    <RecommendationStateContext.Provider value={{recommendationState}}>
      <RecommendationDispatchContext.Provider value={dispatch}>{children}</RecommendationDispatchContext.Provider>
    </RecommendationStateContext.Provider>
  );
}
