import { useReducer } from "react"; 
import ConstantStateHandler from "./ConstantStateHandler";
import StateHandler from "./stateHandler";

export default function handleMouseAction(initialValue, applyHook) {
    let [state, dispatchVal] = useReducer(StateHandler, {
      highLight: initialValue,
    });
    function onMouseEnter(e, type, action) {
      let modifiedState = Object.assign({}, state, {
        highLight: !state.highLight,
      });
      ConstantStateHandler(state, modifiedState, dispatchVal, type, applyHook, action);
    }
    function onMouseLeave(e, type, action) {
      let modifiedState = Object.assign({}, state, {
        highLight: !state.highLight,
      });
      ConstantStateHandler(state, modifiedState, dispatchVal, type, applyHook, action);
    }
    function onFocus(e, type, action) {
      let modifiedState = Object.assign({}, state, {
        highLight: !state.highLight,
      });
      ConstantStateHandler(state, modifiedState, dispatchVal, type, applyHook, action);
    }
    function onBlur(e, type, action) {
      let modifiedState = Object.assign({}, state, {
        highLight: !state.highLight,
      });
      ConstantStateHandler(state, modifiedState, dispatchVal, type, applyHook, action);
    }
    return [state.highLight, onMouseEnter, onMouseLeave, onFocus, onBlur];
}