import { useContext } from "react";
import { ApplicationThemeContext } from "../providers/contexts";
import { COLOR_SCHEME } from "../constants";

const useApplicationTheme = () => {
  const { state, actions } = useContext(ApplicationThemeContext);
  const { onColorSchemeChanged } = actions;

  const { scheme } = state;
  const onDarkModeChanged = active => onColorSchemeChanged(active ? COLOR_SCHEME.DARK : COLOR_SCHEME.LIGHT);

  return { isDark: scheme === COLOR_SCHEME.DARK, onDarkModeChanged };
};

export default useApplicationTheme;
