import React, { useReducer, createContext, useMemo } from "react";
const ViewContext = createContext();

const ACTIONS = {
  UPDATE: "u",
};

const initialState = {
  activePage: "Home",
};

const reducer = (state, action) => {
  // Actions
  switch (action.type) {
    case ACTIONS.UPDATE:
      return { ...state };
    default:
      return state;
  }
};

export const ViewProvider = ({ children }) => {
  const [state, dispatch] = useReducer(reducer, initialState);

  const contextValue = useMemo(() => ({ state, dispatch }), [state, dispatch]);

  return (
    <ViewContext.Provider value={contextValue}>{children}</ViewContext.Provider>
  );
};

export default ViewContext;
