import React, { useCallback, useMemo, useState } from "react";
import { locales } from "@pisell/utils";
import { Iconfont, PisellModal } from "@pisell/materials";
import classNames from "classnames";
//#region src/components/booking/hooks/useClearCart.tsx
const useClearCart = (state, dispatch) => {
	var _state$service3;
	const [open, setOpen] = useState(false);
	const handleOpenModal = useCallback(() => {
		setOpen(true);
	}, []);
	const handleConfirm = useCallback(() => {
		dispatch({
			type: "setService",
			payload: { value: [] }
		});
		setOpen(false);
	}, []);
	const handleCancel = useCallback(() => {
		setOpen(false);
	}, []);
	return useMemo(() => {
		var _state$service, _state$service2;
		const showClearBtn = !!((_state$service = state.service) === null || _state$service === void 0 || (_state$service = _state$service.value) === null || _state$service === void 0 ? void 0 : _state$service.length) && !state.channelDisabledEdit;
		return /* @__PURE__ */ React.createElement(React.Fragment, null, showClearBtn && /* @__PURE__ */ React.createElement("span", {
			className: classNames("pisell-lowcode__booking-service-clear-btn", { ["pisell-lowcode__booking-service-clear-btn-disabled"]: !((_state$service2 = state.service) === null || _state$service2 === void 0 || (_state$service2 = _state$service2.value) === null || _state$service2 === void 0 ? void 0 : _state$service2.length) }),
			onClick: handleOpenModal
		}, /* @__PURE__ */ React.createElement(Iconfont, { type: "pisell2-trash-01" }), " ", /* @__PURE__ */ React.createElement("span", null, locales.getText("pisell2.booking.info.text.clear-cart"))), /* @__PURE__ */ React.createElement(PisellModal, {
			open,
			platform: "pc",
			title: locales.getText("pisell2.booking.info.text.clear-cart-modal.title"),
			onOk: handleConfirm,
			onCancel: handleCancel,
			okText: locales.getText("pisell2.booking.info.text.clear-cart-modal.confirm"),
			cancelText: locales.getText("pisell2.booking.info.text.clear-cart-modal.cancel"),
			destroyOnClose: true
		}, /* @__PURE__ */ React.createElement("div", { style: { margin: "24px 0" } }, /* @__PURE__ */ React.createElement("span", null, locales.getText("pisell2.booking.info.text.clear-cart-modal.content")))));
	}, [
		(_state$service3 = state.service) === null || _state$service3 === void 0 || (_state$service3 = _state$service3.value) === null || _state$service3 === void 0 ? void 0 : _state$service3.length,
		state.channelDisabledEdit,
		open
	]);
};
//#endregion
export { useClearCart as default };
