const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_utils = require("./utils.js");
const require_utils$1 = require("../../../booking/info2/service/addService/utils.js");
const require_index = require("../../utils/index.js");
const require_utils$2 = require("../../../booking/info/service2/Group/utils.js");
const require_utils$3 = require("../../../booking/info/service2/utils.js");
const require_utils$4 = require("../../../booking/utils.js");
const require_utils$5 = require("../../../booking/info/utils.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_selectHolderModal = require("../../../booking/utils/selectHolderModal.js");
const require_openNormalService = require("../../../booking/info2/service/openNormalService.js");
const require_useProducts = require("../../hooks/pisellos/useProducts.js");
const require_IsActiveContext = require("../../context/IsActiveContext.js");
const require_index$1 = require("../../../booking/info/service/serviceManager/index.js");
const require_ProductDisplayAdapter = require("../ProductDisplayAdapter/ProductDisplayAdapter.js");
const require_types = require("../ProductDisplayAdapter/types.js");
const require_index$2 = require("../notAvailable/index.js");
const require_MultiDayTimeSelectModal = require("./MultiDayTimeSelectModal.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let ahooks = require("ahooks");
require("./index.less");
//#region src/components/ticketBooking/components/addServiceVariant/addService.tsx
const productListLayout = {
	grid: true,
	config: "12:12"
};
const productListSetting = {
	isProductCover: 1,
	isTitle: 1,
	isSubtitle: 1,
	isPrice: 1,
	isOriginPrice: 0,
	isStock: 0
};
const AddSerivce = (props) => {
	var _context$appHelper, _context$appHelper$ge, _context$appHelper$ut, _context$appHelper$ut2, _context$appHelper$ut3, _state$bookingConfig2, _state$client2;
	const { onEdit, state, dispatch, renderMode = "current", productDisplayConfig } = props;
	const context = require_useEngineContext.default();
	const notAvailableRef = (0, react.useRef)(null);
	require_utils$4.request.setRequest(context.appHelper.utils.request);
	const isActive = require_IsActiveContext.useIsActive();
	const Toast = (0, _pisell_materials.useToast)();
	const { createBookingData, createBooking } = require_index$1.useService({
		renderMode,
		onEdit,
		state,
		dispatch
	});
	const isBooking4 = require_utils$5.isBooking4Shop(((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper$ge = _context$appHelper.getData) === null || _context$appHelper$ge === void 0 ? void 0 : _context$appHelper$ge.call(_context$appHelper, "shop_id")) || ((_context$appHelper$ut = context.appHelper.utils.store) === null || _context$appHelper$ut === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut.getState) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.call(_context$appHelper$ut)) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.global) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.globalConfig) === null || _context$appHelper$ut2 === void 0 ? void 0 : _context$appHelper$ut2.id), state === null || state === void 0 ? void 0 : state.renderType, (_context$appHelper$ut3 = context.appHelper.utils) === null || _context$appHelper$ut3 === void 0 ? void 0 : _context$appHelper$ut3.businessUtils);
	const [currentProduct, setCurrentProduct] = (0, react.useState)(null);
	const [firstLoading, setFirstLoading] = (0, react.useState)(true);
	const [multiDayModalOpen, setMultiDayModalOpen] = (0, react.useState)(false);
	const [multiDayModalLoading, setMultiDayModalLoading] = (0, react.useState)(false);
	const [pendingMultiDayData, setPendingMultiDayData] = (0, react.useState)(null);
	const stateRef = (0, react.useRef)(state);
	stateRef.current = state;
	const { getProducts, products, loading } = require_useProducts.useProducts(notAvailableRef);
	(0, react.useEffect)(() => {
		const timer = setTimeout(() => {
			setFirstLoading(false);
		}, 300);
		return () => {
			clearTimeout(timer);
		};
	}, []);
	(0, react.useEffect)(() => {
		return () => {
			Object.values(debounceTimersRef.current).forEach((timer) => {
				if (timer) clearTimeout(timer);
			});
			debounceTimersRef.current = {};
		};
	}, []);
	(0, react.useEffect)(() => {
		const handler = (event) => {
			var _event$detail;
			const cacheItem = event === null || event === void 0 || (_event$detail = event.detail) === null || _event$detail === void 0 ? void 0 : _event$detail.cacheItem;
			console.log("Modal closed with result:", event.detail.cacheItem);
			if (!(cacheItem === null || cacheItem === void 0 ? void 0 : cacheItem.id)) return;
			require_index.addServiceScroll(String(cacheItem.id), cacheItem);
		};
		window.addEventListener("onAddNewService", handler);
		return () => {
			window.removeEventListener("onAddNewService", handler);
		};
	}, []);
	const pendingCacheValuesRef = (0, react.useRef)({});
	const clickCountRef = (0, react.useRef)({});
	const debounceTimersRef = (0, react.useRef)({});
	const menuList = (0, react.useMemo)(() => {
		var _state$bookingConfig;
		return (state === null || state === void 0 || (_state$bookingConfig = state.bookingConfig) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.config) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.menu_list_tab) === null || _state$bookingConfig === void 0 ? void 0 : _state$bookingConfig.menu_list) || [];
	}, [state === null || state === void 0 || (_state$bookingConfig2 = state.bookingConfig) === null || _state$bookingConfig2 === void 0 ? void 0 : _state$bookingConfig2.config]);
	const customerId = (0, react.useMemo)(() => {
		var _state$client;
		return ((_state$client = state.client) === null || _state$client === void 0 || (_state$client = _state$client.value) === null || _state$client === void 0 ? void 0 : _state$client.id) || void 0;
	}, [(_state$client2 = state.client) === null || _state$client2 === void 0 || (_state$client2 = _state$client2.value) === null || _state$client2 === void 0 ? void 0 : _state$client2.id]);
	const scanAddService = (0, ahooks.useMemoizedFn)((list, code) => {
		let newService = [...state.service.value];
		list.forEach((item) => {
			if (require_utils.isBundle(item) || require_utils.isOption(item)) {
				handleSelectProduct(item);
				return;
			}
			let cacheItem = require_utils.createCacheItem(item, require_utils.genValues(item, code), state);
			cacheItem._serviceKey = require_index.genServiceKey(cacheItem);
			cacheItem._holderKey = require_index.genHolderKey(cacheItem);
			cacheItem.autoClose = false;
			let { list: _list, quantity } = require_index.addService([...newService], cacheItem, state);
			handleAddToast(cacheItem.title, quantity);
			newService = _list;
		});
		dispatch({
			type: "setService",
			payload: {
				value: newService,
				edit: true
			}
		});
	});
	(0, react.useMemo)(() => {
		if (isActive) require_utils.setHandleSetService(scanAddService);
	}, [isActive]);
	const handleAddToast = (title, quantity) => {
		var _Toast$success;
		Toast === null || Toast === void 0 || (_Toast$success = Toast.success) === null || _Toast$success === void 0 || _Toast$success.call(Toast, /* @__PURE__ */ react.default.createElement("div", { className: "add-toast-wrap" }, /* @__PURE__ */ react.default.createElement("div", { className: "add-toast-title" }, title), /* @__PURE__ */ react.default.createElement("div", { className: "add-toast-quantity" }, _pisell_utils.locales.getText("pisell2.ticket-booking.in-cart")(quantity || 1))));
	};
	const executeCacheValues = (0, ahooks.useMemoizedFn)((productId, originalCacheValues, item, originalCallback) => {
		const clickCount = clickCountRef.current[productId] || 1;
		const finalCacheValues = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, originalCacheValues), {}, { quantity: clickCount });
		delete pendingCacheValuesRef.current[productId];
		delete clickCountRef.current[productId];
		delete debounceTimersRef.current[productId];
		originalCallback(finalCacheValues, "", item, true);
	});
	const debouncedExecuteCacheValues = (0, ahooks.useMemoizedFn)((productId, cacheValues, item, callback) => {
		if (debounceTimersRef.current[productId]) clearTimeout(debounceTimersRef.current[productId]);
		debounceTimersRef.current[productId] = setTimeout(() => {
			executeCacheValues(productId, cacheValues, item, callback);
		}, 0);
	});
	const processAddService = (0, ahooks.useMemoizedFn)(function() {
		var _ref2 = require_asyncToGenerator._asyncToGenerator(function* (item, _detail, e, notShowToast, startDate, endDate) {
			var _detail$_extend, _detail$_extend2, _detail$_extend3, _cacheItem$_extend, _cacheItem$_extend2, _cacheItem$_extend4, _state$client3, _state$bookingConfig3, _state$bookingConfig4;
			const other = JSON.parse(JSON.stringify(e));
			other.session = e.session;
			let cacheItem = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, _detail), {}, {
				product_id: item.id,
				_id: (0, _pisell_utils.getUniqueId)(),
				_key: e.key,
				_extend: {
					start_date: startDate,
					quantity: (e === null || e === void 0 ? void 0 : e.quantity) || 1,
					product_name: item.title,
					other,
					end_date: endDate,
					isNormalProduct: require_utils$3.isNormalProductByDurationSchedule(item),
					note: _detail === null || _detail === void 0 || (_detail$_extend = _detail._extend) === null || _detail$_extend === void 0 ? void 0 : _detail$_extend.note,
					priceOverride: _detail === null || _detail === void 0 || (_detail$_extend2 = _detail._extend) === null || _detail$_extend2 === void 0 ? void 0 : _detail$_extend2.priceOverride,
					origin_total: _detail === null || _detail === void 0 || (_detail$_extend3 = _detail._extend) === null || _detail$_extend3 === void 0 ? void 0 : _detail$_extend3.origin_total
				},
				new: 1
			});
			cacheItem._extend.price = require_utils$4.getMainPrice(_detail, _detail.price);
			if (((_cacheItem$_extend = cacheItem._extend) === null || _cacheItem$_extend === void 0 ? void 0 : _cacheItem$_extend.priceOverride) || ((_cacheItem$_extend2 = cacheItem._extend) === null || _cacheItem$_extend2 === void 0 ? void 0 : _cacheItem$_extend2.priceOverride) === 0) {
				var _cacheItem$_extend3;
				cacheItem._extend.price = (_cacheItem$_extend3 = cacheItem._extend) === null || _cacheItem$_extend3 === void 0 ? void 0 : _cacheItem$_extend3.priceOverride;
			}
			let _total = require_utils$4.getProductTotalPrice(cacheItem);
			cacheItem._extend.total = _total;
			if (!((_cacheItem$_extend4 = cacheItem._extend) === null || _cacheItem$_extend4 === void 0 ? void 0 : _cacheItem$_extend4.origin_total)) cacheItem._extend.origin_total = _total;
			if (!!stateRef.current.service.cacheItem) {
				var _stateRef$current$ser;
				cacheItem._id = (_stateRef$current$ser = stateRef.current.service.cacheItem) === null || _stateRef$current$ser === void 0 ? void 0 : _stateRef$current$ser._id;
				cacheItem.new = 0;
			}
			if (renderMode === "current") cacheItem.currentDefaultTime = stateRef.current.date.value.format("HH:mm");
			cacheItem = require_utils$1.getProductExtend({
				cacheItem,
				state: stateRef.current,
				isDisabledTime: true
			});
			const isMultiDay = require_utils$1.isMultiDayProduct(cacheItem);
			const getMultiDayCacheItem = function() {
				var _ref = require_asyncToGenerator._asyncToGenerator(function* (isConcatBookings) {
					cacheItem = yield require_utils$1.getMultiDay({
						start_date: cacheItem._extend.start_date,
						end_date: cacheItem._extend.end_date,
						state: stateRef.current,
						cacheItem
					});
					cacheItem = require_utils$2.createBookingItemsByGroup(cacheItem);
					if (isConcatBookings) cacheItem = require_utils$2.concatBookings(cacheItem);
				});
				return function getMultiDayCacheItem(_x) {
					return _ref.apply(this, arguments);
				};
			}();
			if (!require_utils$3.isNormalProductByDurationSchedule(cacheItem) && (!cacheItem._extend.holder_id || !cacheItem._extend.holder_id.length) && !require_utils$4.isWalkIn((_state$client3 = state.client) === null || _state$client3 === void 0 || (_state$client3 = _state$client3.value) === null || _state$client3 === void 0 ? void 0 : _state$client3.id) && (state === null || state === void 0 || (_state$bookingConfig3 = state.bookingConfig) === null || _state$bookingConfig3 === void 0 || (_state$bookingConfig3 = _state$bookingConfig3.config) === null || _state$bookingConfig3 === void 0 || (_state$bookingConfig3 = _state$bookingConfig3.basic) === null || _state$bookingConfig3 === void 0 || (_state$bookingConfig3 = _state$bookingConfig3.appointment_subject) === null || _state$bookingConfig3 === void 0 ? void 0 : _state$bookingConfig3.type) === "form" && (state === null || state === void 0 || (_state$bookingConfig4 = state.bookingConfig) === null || _state$bookingConfig4 === void 0 || (_state$bookingConfig4 = _state$bookingConfig4.config) === null || _state$bookingConfig4 === void 0 || (_state$bookingConfig4 = _state$bookingConfig4.basic) === null || _state$bookingConfig4 === void 0 || (_state$bookingConfig4 = _state$bookingConfig4.appointment_subject) === null || _state$bookingConfig4 === void 0 ? void 0 : _state$bookingConfig4.show_hold_on_add_cart) !== 0) {
				const res = yield handleAddHolder(cacheItem);
				if (res && res.length > 0) cacheItem._extend.holder_id = res;
				else {
					var _state$bookingConfig5;
					if ((state === null || state === void 0 || (_state$bookingConfig5 = state.bookingConfig) === null || _state$bookingConfig5 === void 0 || (_state$bookingConfig5 = _state$bookingConfig5.config) === null || _state$bookingConfig5 === void 0 || (_state$bookingConfig5 = _state$bookingConfig5.basic) === null || _state$bookingConfig5 === void 0 ? void 0 : _state$bookingConfig5.subject_require) === "require") return;
				}
			}
			if (stateRef.current.renderType === "eventBooking") cacheItem.autoClose = false;
			if (cacheItem.autoClose) {
				cacheItem.autoClose = false;
				cacheItem._serviceKey = require_index.genServiceKey(cacheItem);
				cacheItem._holderKey = require_index.genHolderKey(cacheItem);
				if (isMultiDay) yield getMultiDayCacheItem();
				let { list: _list, quantity } = require_index.addService([...stateRef.current.service.value], cacheItem, stateRef.current, isMultiDay);
				if (!notShowToast) handleAddToast(cacheItem.title, quantity || 1);
				window.dispatchEvent(new CustomEvent("onAddNewService", { detail: { cacheItem } }));
				try {
					var _context$appHelper$ut4, _context$appHelper$ut5;
					if (((_context$appHelper$ut4 = context.appHelper.utils.store) === null || _context$appHelper$ut4 === void 0 || (_context$appHelper$ut5 = _context$appHelper$ut4.getState) === null || _context$appHelper$ut5 === void 0 || (_context$appHelper$ut5 = _context$appHelper$ut5.call(_context$appHelper$ut4)) === null || _context$appHelper$ut5 === void 0 || (_context$appHelper$ut5 = _context$appHelper$ut5.global) === null || _context$appHelper$ut5 === void 0 || (_context$appHelper$ut5 = _context$appHelper$ut5.globalConfig) === null || _context$appHelper$ut5 === void 0 ? void 0 : _context$appHelper$ut5.id) === 2155) {
						const val = _list === null || _list === void 0 ? void 0 : _list.map((s) => {
							return {
								product_id: s === null || s === void 0 ? void 0 : s.product_id,
								detailId: s === null || s === void 0 ? void 0 : s.id,
								detailProductId: s === null || s === void 0 ? void 0 : s.product_id,
								product_name: s === null || s === void 0 ? void 0 : s.title,
								price: s === null || s === void 0 ? void 0 : s.price,
								_id: s === null || s === void 0 ? void 0 : s._id,
								_key: s === null || s === void 0 ? void 0 : s._key,
								_serviceKey: s === null || s === void 0 ? void 0 : s._serviceKey,
								_holderKey: s === null || s === void 0 ? void 0 : s._holderKey
							};
						});
						const sendData = {
							product_id: item === null || item === void 0 ? void 0 : item.id,
							detailId: _detail === null || _detail === void 0 ? void 0 : _detail.id,
							detailProductId: _detail === null || _detail === void 0 ? void 0 : _detail.product_id,
							product_name: item === null || item === void 0 ? void 0 : item.title,
							price: _detail === null || _detail === void 0 ? void 0 : _detail.price,
							serviceVal: val
						};
						(0, _pisell_utils.sendWarningLog)({
							title: "addService",
							content: [{
								key: "添加数据",
								value: JSON.stringify(sendData)
							}, {
								key: "日期",
								value: (0, dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
							}]
						});
					}
				} catch (error) {}
				dispatch({
					type: "setService",
					payload: {
						addModal: false,
						value: _list,
						edit: true,
						changeService: false
					}
				});
			} else {
				var _window$openBookingEd, _window;
				(_window$openBookingEd = (_window = window).openBookingEditModal) === null || _window$openBookingEd === void 0 || _window$openBookingEd.call(_window);
				if (isMultiDay) yield getMultiDayCacheItem(true);
				dispatch({
					type: "setService",
					payload: {
						editModal: true,
						cacheItem,
						addModal: !cacheItem.autoClose,
						changeService: false
					}
				});
				onEdit === null || onEdit === void 0 || onEdit(cacheItem);
			}
		});
		return function(_x2, _x3, _x4, _x5, _x6, _x7) {
			return _ref2.apply(this, arguments);
		};
	}());
	const handleMultiDayConfirm = (0, ahooks.useMemoizedFn)(function() {
		var _ref3 = require_asyncToGenerator._asyncToGenerator(function* (startDate, endDate, duration) {
			if (!pendingMultiDayData) return;
			setMultiDayModalLoading(true);
			try {
				const { item, detail, e, notShowToast } = pendingMultiDayData;
				yield processAddService(item, detail, e, notShowToast, startDate, endDate);
				setPendingMultiDayData(null);
				setMultiDayModalOpen(false);
			} catch (error) {
				console.error("添加跨日商品失败:", error);
			} finally {
				setMultiDayModalLoading(false);
			}
		});
		return function(_x8, _x9, _x10) {
			return _ref3.apply(this, arguments);
		};
	}());
	const handleMultiDayCancel = (0, ahooks.useMemoizedFn)(() => {
		setMultiDayModalOpen(false);
		setPendingMultiDayData(null);
	});
	const handleAddHolder = (0, ahooks.useMemoizedFn)(function() {
		var _ref4 = require_asyncToGenerator._asyncToGenerator(function* (cacheItem) {
			var _stateRef$current, _cacheItem$_extend5;
			const holderConfig = ((_stateRef$current = stateRef.current) === null || _stateRef$current === void 0 || (_stateRef$current = _stateRef$current.bookingConfig) === null || _stateRef$current === void 0 ? void 0 : _stateRef$current.holder) || {};
			const currentMaxSelectedCount = (holderConfig === null || holderConfig === void 0 ? void 0 : holderConfig.maxSelectedCount) || (cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend5 = cacheItem._extend) === null || _cacheItem$_extend5 === void 0 ? void 0 : _cacheItem$_extend5.quantity) || 1;
			return yield require_selectHolderModal.selectHolderModal({
				state: stateRef.current,
				dispatch,
				maxSelectedCount: currentMaxSelectedCount
			});
		});
		return function(_x11) {
			return _ref4.apply(this, arguments);
		};
	}());
	const handleSelectProduct = (0, ahooks.useMemoizedFn)((item, type = "select") => {
		console.log("handleSelectProduct");
		if (!require_utils$3.isNormalProductByDurationSchedule(item)) {
			var _state$service;
			if (!Array.isArray((_state$service = state.service) === null || _state$service === void 0 ? void 0 : _state$service.resourcesOrigin) || !state.service.resourcesOrigin.length) {
				dispatch({
					type: "setService",
					payload: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, stateRef.current.service), {}, { reloadResourceModal: true })
				});
				return;
			}
		}
		const isSession = require_utils$4.isSessionProduct(item);
		const isEject = require_utils$4.getIsEject(item, type);
		const isOnlySession = require_utils$4.getIsOnlySession(item);
		let lock = false;
		let cacheValues = null;
		if (isEject) setCurrentProduct(item);
		else {
			setCurrentProduct(null);
			if ((item === null || item === void 0 ? void 0 : item.extension_type) === "normal") cacheValues = {
				bundle: [],
				key: item.id,
				option: [],
				product_id: item.id,
				product_variant_id: 0,
				quantity: 1,
				rowKey: item.id,
				session: null,
				unique: "08974625397",
				_originalItem: item
			};
		}
		const callback = function() {
			var _ref5 = require_asyncToGenerator._asyncToGenerator(function* (e, extension_type, detail, notShowToast) {
				setCurrentProduct(null);
				if (lock) return;
				lock = true;
				setTimeout(() => {
					lock = false;
				}, 2e3);
				if (!isBooking4) {
					createBooking({ booking: yield createBookingData({ product: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, detail || item), {}, { _params: e }) }) });
					return;
				}
				const _detail = detail || item;
				if (require_utils$1.isMultiDayProduct(_detail || item)) {
					setPendingMultiDayData({
						item,
						detail: _detail,
						e,
						notShowToast
					});
					setMultiDayModalOpen(true);
					return;
				}
				yield processAddService(item, _detail, e, notShowToast, state.date.value);
			});
			return function callback(_x12, _x13, _x14, _x15) {
				return _ref5.apply(this, arguments);
			};
		}();
		if (cacheValues) {
			var _stateRef$current$ser2, _detail$_extend4, _Toast$success2;
			const productId = item.id.toString();
			if (pendingCacheValuesRef.current[productId]) clickCountRef.current[productId] = (clickCountRef.current[productId] || 1) + 1;
			else {
				pendingCacheValuesRef.current[productId] = cacheValues;
				clickCountRef.current[productId] = 1;
			}
			const cacheItem = require_index.createSimpleCacheItem(item, cacheValues, state);
			const detail = (_stateRef$current$ser2 = stateRef.current.service.value) === null || _stateRef$current$ser2 === void 0 ? void 0 : _stateRef$current$ser2.find((val) => require_index.isSameProduct(val, cacheItem));
			const originalQuantity = (detail === null || detail === void 0 || (_detail$_extend4 = detail._extend) === null || _detail$_extend4 === void 0 ? void 0 : _detail$_extend4.quantity) || 0;
			Toast === null || Toast === void 0 || (_Toast$success2 = Toast.success) === null || _Toast$success2 === void 0 || _Toast$success2.call(Toast, /* @__PURE__ */ react.default.createElement("div", { className: "add-toast-wrap" }, /* @__PURE__ */ react.default.createElement("div", { className: "add-toast-title" }, item.title), /* @__PURE__ */ react.default.createElement("div", { className: "add-toast-quantity" }, _pisell_utils.locales.getText("pisell2.ticket-booking.in-cart")((clickCountRef.current[productId] || 1) + originalQuantity))));
			debouncedExecuteCacheValues(productId, cacheValues, item, callback);
			return;
		}
		if (require_utils$3.isNormalProductByDurationSchedule(item)) {
			const openNormalService = require_openNormalService.getOpenNormalServiceHandler();
			if (openNormalService) openNormalService({
				mode: "create",
				productId: item.id,
				date: state.date.value.format("YYYY-MM-DD"),
				isEject: isEject ? 1 : 0,
				onClose: () => {
					setCurrentProduct(null);
				},
				callback
			});
		} else state.action({
			type: "pisell1.handleOpenProductModal",
			data: {
				id: item.id,
				date: state.date.value.format("YYYY-MM-DD"),
				showConfig: {
					option: true,
					session: isSession,
					variant: true,
					package: true,
					number: require_index.getIsShowNumber(item, state)
				},
				isOnlySession,
				is_eject: isEject ? 1 : 0,
				customer_id: customerId,
				isOS: isSession
			},
			onCancel: () => {
				setCurrentProduct(null);
			},
			callback
		});
	});
	const renderList = (0, react.useMemo)(() => {
		return products || [];
	}, [products, state === null || state === void 0 ? void 0 : state.activeCartId]);
	const currentDate = (0, react.useMemo)(() => {
		return state.date.value.format("YYYY-MM-DD");
	}, [state.date.value]);
	const currentDatetime = (0, react.useMemo)(() => {
		return state.date.value.format("YYYY-MM-DD HH:mm:ss");
	}, [state.date.value]);
	(0, react.useEffect)(() => {
		if (renderMode === "current" && state.bookingConfig) getProducts({
			schedule_date: currentDate,
			customer_id: customerId,
			menu_list_ids: menuList,
			schedule_datetime: currentDatetime
		});
	}, [
		renderMode,
		currentDate,
		customerId,
		menuList,
		currentDatetime
	]);
	const finalDisplayConfig = (0, react.useMemo)(() => {
		const resolvedConfig = require_types.resolveProductDisplayConfig(productDisplayConfig);
		if (resolvedConfig.displayMode === "product-select") {
			var _resolvedConfig$produ, _resolvedConfig$produ2;
			return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, resolvedConfig), {}, { productSelectConfig: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, resolvedConfig.productSelectConfig), {}, {
				layout: ((_resolvedConfig$produ = resolvedConfig.productSelectConfig) === null || _resolvedConfig$produ === void 0 ? void 0 : _resolvedConfig$produ.layout) || productListLayout,
				productListSetting: ((_resolvedConfig$produ2 = resolvedConfig.productSelectConfig) === null || _resolvedConfig$produ2 === void 0 ? void 0 : _resolvedConfig$produ2.productListSetting) || productListSetting
			}) });
		}
		return resolvedConfig;
	}, [productDisplayConfig]);
	return (0, react.useMemo)(() => {
		if (renderMode === "current") {
			var _pendingMultiDayData$;
			return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(require_ProductDisplayAdapter.default, {
				config: finalDisplayConfig,
				dataSource: renderList,
				loading: !renderList.length && loading || firstLoading,
				currentProductId: currentProduct === null || currentProduct === void 0 ? void 0 : currentProduct.id,
				onSelectProduct: handleSelectProduct
			}), /* @__PURE__ */ react.default.createElement(require_index$2.default, { ref: notAvailableRef }), /* @__PURE__ */ react.default.createElement(require_MultiDayTimeSelectModal.default, {
				open: multiDayModalOpen,
				productName: pendingMultiDayData === null || pendingMultiDayData === void 0 || (_pendingMultiDayData$ = pendingMultiDayData.item) === null || _pendingMultiDayData$ === void 0 ? void 0 : _pendingMultiDayData$.title,
				locale: state === null || state === void 0 ? void 0 : state.locale,
				defaultStartDate: state.date.value,
				loading: multiDayModalLoading,
				onConfirm: handleMultiDayConfirm,
				onCancel: handleMultiDayCancel
			}), /* @__PURE__ */ react.default.createElement(require_selectHolderModal.SelectHolderModal, null));
		}
		return null;
	}, [
		firstLoading,
		state.service.addModal,
		_pisell_utils.locales,
		renderList,
		state.amountSymbol,
		state.renderType,
		state === null || state === void 0 ? void 0 : state.activeCartId,
		require_utils$3.holderId(state),
		loading,
		currentProduct,
		isBooking4,
		finalDisplayConfig,
		multiDayModalOpen,
		pendingMultiDayData,
		multiDayModalLoading
	]);
};
//#endregion
exports.default = AddSerivce;
