const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_status = require("./status.js");
const require_utils = require("./utils.js");
let react = require("react");
react = require_runtime.__toESM(react);
//#region src/components/shoppingCart/Provider.tsx
const CartContext = (0, react.createContext)({});
const CartProvider = ({ children, props, onCard, onAction, onChange, onAddProduct, onActiveKey }) => {
	const defaultState = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, require_status.defaultData), props);
	const [state, setState] = (0, react.useState)(defaultState);
	/**
	* @title: 更新数据
	* @description:
	* @param {any} newState
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-11-28 14:44
	*/
	const updateState = (newState) => {
		console.log(newState, "wh_new");
		setState((prevState) => {
			return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, prevState), newState);
		});
	};
	/**
	* @title: 更新配置
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-11-28 18:40
	*/
	(0, react.useEffect)(() => {
		const _isOpenGroup = props === null || props === void 0 ? void 0 : props.hasOwnProperty("isOpenGroup");
		let newState = {};
		if (props === null || props === void 0 ? void 0 : props.platform) newState["platform"] = props === null || props === void 0 ? void 0 : props.platform;
		if (_isOpenGroup) newState["isOpenGroup"] = props === null || props === void 0 ? void 0 : props.isOpenGroup;
		if (props === null || props === void 0 ? void 0 : props.emptyText) newState["emptyText"] = props === null || props === void 0 ? void 0 : props.emptyText;
		if (props === null || props === void 0 ? void 0 : props.productParams) newState = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, newState), props === null || props === void 0 ? void 0 : props.productParams);
		if (props === null || props === void 0 ? void 0 : props.collapseParams) newState["collapseParams"] = props === null || props === void 0 ? void 0 : props.collapseParams;
		const params = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, defaultState), newState);
		setState(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, params), require_utils.formatState(params)));
	}, [
		props === null || props === void 0 ? void 0 : props.platform,
		props === null || props === void 0 ? void 0 : props.isOpenGroup,
		props === null || props === void 0 ? void 0 : props.emptyText,
		props === null || props === void 0 ? void 0 : props.productParams,
		props === null || props === void 0 ? void 0 : props.collapseParams
	]);
	return /* @__PURE__ */ react.default.createElement(CartContext.Provider, { value: {
		state,
		updateState,
		onCard,
		onChange,
		onAddProduct,
		onActiveKey,
		onAction
	} }, children);
};
//#endregion
exports.CartContext = CartContext;
exports.CartProvider = CartProvider;
