import { _objectSpread2 } from "../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import React, { createContext, useCallback, useReducer } from "react";
//#region src/utils/miniRedux.tsx
var miniRedux_default = ({ namespace = "state", state, reducers = {}, effects = {} }) => {
	const Context = createContext({});
	const Provider = (ComponentUi) => {
		const Components = (props, ref) => {
			const [providerState, dispatch] = useReducer((state, { type, payload }) => {
				if (reducers[type]) return reducers[type](state, payload);
				else return state;
			}, state);
			const _dispatch = useCallback(({ type, payload }) => {
				if (effects[type]) effects[type].call(null, payload, dispatch);
				else if (reducers[type]) dispatch({
					type,
					payload
				});
			}, []);
			let _props = _objectSpread2(_objectSpread2({}, props), {}, {
				[namespace]: providerState,
				dispatch: _dispatch
			});
			let _ref = ref;
			return /* @__PURE__ */ React.createElement(Context.Provider, { value: {
				[namespace]: providerState,
				dispatch: _dispatch
			} }, /* @__PURE__ */ React.createElement(ComponentUi, _objectSpread2(_objectSpread2({}, _props), {}, { ref: _ref })));
		};
		return Components;
	};
	return {
		Context,
		Provider
	};
};
//#endregion
export { miniRedux_default as default };
