import React, { createContext, useReducer } from 'react'
import { Appearance, useColorScheme } from 'react-native';

const ThemeContext = createContext()



const themeReducer = (state, action) => {
  switch (action.type) {
    case "LIGHTMODE":
      return { theme: 'light' };
    case "DARKMODE":
      return { theme: 'dark' };
    default:
      return state;
  }
};

const ThemeProvider = ({ children }) => {

  const initialState = {
    theme: Appearance.getColorScheme()
  }

  const [state, dispatch] = useReducer(themeReducer, initialState);
  return (
    <ThemeContext.Provider
      value={{ state: state, dispatch: dispatch }}
    >
      {children}
    </ThemeContext.Provider>
  )
}

export {
  ThemeContext,
  ThemeProvider
}