import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { defaultData } from "./status.js";
import { formatState } from "./utils.js";
import React, { createContext, useEffect, useState } from "react";
//#region src/components/shoppingCart/Provider.tsx
const CartContext = createContext({});
const CartProvider = ({ children, props, onCard, onAction, onChange, onAddProduct, onActiveKey }) => {
	const defaultState = _objectSpread2(_objectSpread2({}, defaultData), props);
	const [state, setState] = 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 _objectSpread2(_objectSpread2({}, prevState), newState);
		});
	};
	/**
	* @title: 更新配置
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-11-28 18:40
	*/
	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 = _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 = _objectSpread2(_objectSpread2({}, defaultState), newState);
		setState(_objectSpread2(_objectSpread2({}, params), 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.createElement(CartContext.Provider, { value: {
		state,
		updateState,
		onCard,
		onChange,
		onAddProduct,
		onActiveKey,
		onAction
	} }, children);
};
//#endregion
export { CartContext, CartProvider };
