import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import locales_default from "../../locales.js";
import { useContext as useContext$1 } from "../../hooks/useContext.js";
import Empty$1 from "../Empty/index.js";
import Product from "./Product.js";
import React, { useMemo } from "react";
import { locales } from "@pisell/utils";
import { Collapse } from "@pisell/materials";
import classNames from "classnames";
import "./index.less";
//#region src/components/shoppingCart/components/Cart/index.tsx
locales.init(locales_default, localStorage.getItem("umi_locale") || "en");
const Cart = () => {
	const { state, updateState, onActiveKey } = useContext$1();
	const { platform, carts, isProductList, collapseParams } = state;
	/**
	* @title: 折叠面板
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-11-27 15:01
	*/
	const cartsMap = useMemo(() => {
		return carts === null || carts === void 0 ? void 0 : carts.map((item) => {
			var _item$products, _item$products2, _item$products3;
			const _length = item === null || item === void 0 || (_item$products = item.products) === null || _item$products === void 0 ? void 0 : _item$products.length;
			return _objectSpread2(_objectSpread2({}, item), {}, {
				label: /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__shopping-cart-label" }, `${item === null || item === void 0 ? void 0 : item.label} ${locales.getText("pisell2.text.shopping-cart.item")(item === null || item === void 0 || (_item$products2 = item.products) === null || _item$products2 === void 0 ? void 0 : _item$products2.length)}`),
				children: (item === null || item === void 0 || (_item$products3 = item.products) === null || _item$products3 === void 0 ? void 0 : _item$products3.length) > 0 ? /* @__PURE__ */ React.createElement(Product, {
					id: item === null || item === void 0 ? void 0 : item.key,
					lists: item === null || item === void 0 ? void 0 : item.products,
					isAdd: state.maxLength > _length
				}) : /* @__PURE__ */ React.createElement(Empty$1, { id: item === null || item === void 0 ? void 0 : item.key }),
				showArrow: platform === "shop"
			});
		});
	}, [carts, platform]);
	return useMemo(() => {
		console.log("render cart 22222", state.prodcuts);
		return /* @__PURE__ */ React.createElement("div", { className: classNames("pisell-lowcode__shopping-cart") }, isProductList ? /* @__PURE__ */ React.createElement(Product, {
			id: void 0,
			lists: state === null || state === void 0 ? void 0 : state.products
		}) : /* @__PURE__ */ React.createElement(Collapse, _objectSpread2({
			items: cartsMap,
			showHeader: true,
			panelBackground: "#ffffff",
			collapsible: platform !== "shop" ? "disabled" : "-",
			accordion: platform === "shop",
			onChange: (key) => {
				updateState({ activeKey: key });
				onActiveKey(key);
			}
		}, collapseParams)));
	}, [
		isProductList,
		cartsMap,
		platform,
		collapseParams,
		state === null || state === void 0 ? void 0 : state.products
	]);
};
//#endregion
export { Cart as default };
