import ConstantHandler from "./constantsHandler";

export default function ConstantStateHandler(
    state,
    modifiedState,
    dispatchVal,
    type,
    applyHook,
    actionVal
  ) {
    let component = type.split("_").length > 2 ? type.split("_") : null;
    let type1 = component.length
      ? ConstantHandler(type, component[component.length - 1].toLowerCase())
      : type;
    dispatchVal(
      { type: type1, data: modifiedState },
      actionVal && actionVal(modifiedState)
    );
    if (applyHook) {
      let newState = applyHook(state, modifiedState, type);
      dispatchVal(
        { type: type1, data: newState },
        actionVal && actionVal(newState)
      );
    }
}