const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_utils = require("../../info2/service/addService/utils.js");
const require_utils$1 = require("../service2/utils.js");
const require_model = require("../model.js");
const require_useHolderConfig = require("../hooks/useHolderConfig.js");
const require_Provider = require("../../../shoppingCart/Provider.js");
const require_index = require("../../../shoppingCart/index.js");
const require_useAddHolder = require("../hooks/useAddHolder.js");
let react = require("react");
react = require_runtime.__toESM(react);
let ahooks = require("ahooks");
//#region src/components/booking/info/service/Lists.tsx
const Lists = ({ onEdit, onChange, onAction, isParallelResource, isShowDelete = true, isShowAmountFooter = true }) => {
	var _state$service2;
	const { state, dispatch } = (0, react.useContext)(require_model.Context);
	const { isShowChangeHolder } = require_useHolderConfig.default(state);
	const { handleAddHolder } = require_useAddHolder.default(state, dispatch);
	/**
	* @title: 更新商品数据
	* @description:
	* @param {any} newState
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-11-29 16:35
	*/
	const handleChange = (0, ahooks.useMemoizedFn)((currentItem, type, other) => {
		var _window$closeBookingE, _window2;
		console.time("handleChange");
		console.log(window.pp1 = performance.now(), "打开商品");
		if (state.disabledEdit || state.disableEventBookingEdit) return;
		let products = require_utils$1.updateServices(state, currentItem, type, other, { handleAddHolder });
		if (type === "view" || type === "edit_product") {
			let product = currentItem._origin;
			let cacheItem = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, product), {}, { new: 0 });
			if (isParallelResource && !require_utils$1.isNormalProductByDurationSchedule(product)) cacheItem = require_utils.getProductExtend({
				cacheItem,
				state
			});
			if (!require_utils$1.isNormalProductByDurationSchedule(cacheItem)) {
				var _window$openBookingEd, _window;
				(_window$openBookingEd = (_window = window).openBookingEditModal) === null || _window$openBookingEd === void 0 || _window$openBookingEd.call(_window);
				onChange({
					editModal: true,
					cacheItem
				});
			}
			return onEdit === null || onEdit === void 0 ? void 0 : onEdit(cacheItem, type);
		}
		(_window$closeBookingE = (_window2 = window).closeBookingEditModal) === null || _window$closeBookingE === void 0 || _window$closeBookingE.call(_window2);
		onChange({
			editModal: false,
			value: products,
			edit: true,
			cacheItem: null
		});
	});
	/**
	* @title: 商品信息
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-09 16:07
	*/
	const productParams = (0, react.useMemo)(() => {
		var _state$bookingConfig;
		return {
			hideAddBtn: state.isTerminalDayBookingPage || state.isBookingCreatePage,
			isShowNote: state.isBookingTicket2 ? true : require_utils$1.isEventBooking(state),
			isShowDelete,
			isShowAmountFooter,
			isShowPackageNote: false,
			accounts: [],
			isEdit: !!(state === null || state === void 0 ? void 0 : state.bookingId),
			disabledEdit: state === null || state === void 0 ? void 0 : state.disabledEdit,
			maxLength: require_utils$1.isEventBooking(state) ? 1 : 999,
			isShowChangeHolder,
			isShowChangeResource: true,
			isShowAddHolderButton: true,
			isShowEditProduct: !state.isBookingCreatePage,
			productCardStyleConfig: (_state$bookingConfig = state.bookingConfig) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.config) === null || _state$bookingConfig === void 0 ? void 0 : _state$bookingConfig.cart_settings_tab
		};
	}, [
		state === null || state === void 0 ? void 0 : state.bookingId,
		state === null || state === void 0 ? void 0 : state.disabledEdit,
		isShowChangeHolder,
		state.isBookingCreatePage,
		state.bookingConfig
	]);
	const products = (0, react.useMemo)(() => {
		var _state$service;
		console.time("products");
		const p = require_utils$1.formatProducts((state === null || state === void 0 || (_state$service = state.service) === null || _state$service === void 0 ? void 0 : _state$service.value) || [], state, true, true, isParallelResource);
		console.timeEnd("products");
		return p;
	}, [state === null || state === void 0 || (_state$service2 = state.service) === null || _state$service2 === void 0 ? void 0 : _state$service2.value, state]);
	return (0, react.useMemo)(() => {
		console.log("render List");
		return /* @__PURE__ */ react.default.createElement(require_Provider.CartContext.Provider, { value: { state } }, /* @__PURE__ */ react.default.createElement(require_index.default, {
			scenario: state.isBookingTicket2 ? "booking2" : void 0,
			isParallelResource,
			onAction,
			onChange: handleChange,
			isOpenGroup: false,
			isHideClearCart: true,
			onAddProduct: () => onChange({ addModal: true }),
			productParams: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, productParams), {}, { products })
		}));
	}, [
		products,
		state,
		productParams
	]);
};
//#endregion
exports.default = Lists;
