import { useContext as useContext$1 } from "../../hooks/useContext.js";
import Empty from "../Empty/index.js";
import SelectHolderModal_default from "../SelectHolderModal/index.js";
import Cart from "../Cart/index.js";
import React, { useEffect, useRef, useState } from "react";
import classNames from "classnames";
import "./index.less";
//#region src/components/shoppingCart/components/Render/index.tsx
const Content = () => {
	const { state, onChange } = useContext$1();
	const selectPetRef = useRef();
	const [pet, setPet] = useState([]);
	const { isEmpty, className, holders, products, isEdit, platform } = state;
	/**
	* @title: 监听holder发生变化
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-09 18:06
	*/
	useEffect(() => {
		let _holders = holders === null || holders === void 0 ? void 0 : holders.filter((item) => (item === null || item === void 0 ? void 0 : item.key) > 0);
		if ((_holders === null || _holders === void 0 ? void 0 : _holders.length) && !(pet === null || pet === void 0 ? void 0 : pet.length) && (products === null || products === void 0 ? void 0 : products.length) && !isEdit && platform !== "h5") if (_holders.length === 1) {
			var _holders$;
			onChange(products, "update_holders", (_holders$ = _holders[0]) === null || _holders$ === void 0 ? void 0 : _holders$.key);
			return;
		} else {
			var _selectPetRef$current, _selectPetRef$current2;
			(_selectPetRef$current = selectPetRef.current) === null || _selectPetRef$current === void 0 || (_selectPetRef$current2 = _selectPetRef$current.open) === null || _selectPetRef$current2 === void 0 || _selectPetRef$current2.call(_selectPetRef$current, {
				products,
				holders
			});
		}
		setPet(_holders);
	}, [holders]);
	return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: classNames("pisell-lowcode__shopping-cart-wrap", className) }, isEmpty ? /* @__PURE__ */ React.createElement(Empty, null) : /* @__PURE__ */ React.createElement(Cart, null)), /* @__PURE__ */ React.createElement(SelectHolderModal_default, {
		ref: selectPetRef,
		onChange
	}));
};
//#endregion
export { Content as default };
