const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_useContext = require("./useContext.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
//#region src/components/shoppingCart/hooks/useClearCart.tsx
const useClearCart = (key) => {
	const [open, setOpen] = (0, react.useState)(false);
	const { state, onChange } = require_useContext.useContext();
	const { isProductList, disabledEdit, holders, isHideClearCart } = state;
	/**
	* @title: 清空购物车
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-11-28 22:47
	*/
	const handleClear = () => {
		let products = [...(state === null || state === void 0 ? void 0 : state.products) || []];
		if (typeof key === "undefined") products = [];
		else {
			onChange(products === null || products === void 0 ? void 0 : products.map((item) => item === null || item === void 0 ? void 0 : item._id), "delete_holders", key);
			setOpen(false);
			return;
		}
	};
	const handleOpenModal = (0, react.useCallback)(() => {
		setOpen(true);
	}, []);
	const handleCancel = (0, react.useCallback)(() => {
		setOpen(false);
	}, []);
	return (0, react.useMemo)(() => {
		const showClearBtn = !disabledEdit && (holders === null || holders === void 0 ? void 0 : holders.length) > 0 && !isHideClearCart;
		return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, showClearBtn ? /* @__PURE__ */ react.default.createElement("span", {
			className: (0, classnames.default)("pisell-lowcode__shopping-cart-clear-btn", { "pisell-lowcode__shopping-cart-clear-btn-empty": isProductList }),
			onClick: handleOpenModal
		}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-trash-01" }), /* @__PURE__ */ react.default.createElement("span", null, _pisell_utils.locales.getText("pisell2.booking.info.text.clear-cart"))) : null, /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellModal, {
			open,
			title: _pisell_utils.locales.getText("pisell2.booking.info.text.clear-cart-modal.title"),
			onOk: handleClear,
			onCancel: handleCancel,
			okText: _pisell_utils.locales.getText("pisell2.booking.info.text.clear-cart-modal.confirm"),
			cancelText: _pisell_utils.locales.getText("pisell2.booking.info.text.clear-cart-modal.cancel"),
			destroyOnClose: true
		}, /* @__PURE__ */ react.default.createElement("div", { style: { margin: "24px 0" } }, /* @__PURE__ */ react.default.createElement("span", null, _pisell_utils.locales.getText("pisell2.booking.info.text.clear-cart-modal.content")))));
	}, [
		open,
		disabledEdit,
		holders === null || holders === void 0 ? void 0 : holders.length,
		isHideClearCart,
		isProductList
	]);
};
//#endregion
exports.default = useClearCart;
