require("../../../_virtual/_rolldown/runtime.js");
let react = require("react");
//#region src/components/eftposPay/store/useThunkReducer.ts
function useThunkReducer(reducer, initialArg, init) {
	const [hookState, setHookState] = (0, react.useState)(init ? init(initialArg) : initialArg);
	const state = (0, react.useRef)(hookState);
	const getState = (0, react.useCallback)(() => state.current, [state]);
	const setState = (0, react.useCallback)((newState) => {
		state.current = newState;
		setHookState(newState);
	}, [state, setHookState]);
	const reduce = (0, react.useCallback)((action) => reducer(getState(), action), [reducer, getState]);
	const dispatch = (0, react.useCallback)((action) => {
		if (typeof action === "function") return action(dispatch, getState);
		setState(reduce(action));
	}, [
		getState,
		setState,
		reduce
	]);
	return [hookState, dispatch];
}
//#endregion
exports.default = useThunkReducer;
