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