const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_status = require("./status.js");
const require_utils = require("./utils.js");
const require_model = require("../model.js");
const require_useSelectPet = require("./hooks/useSelectPet.js");
const require_Provider = require("../../../shoppingCart/Provider.js");
const require_index = require("../../../shoppingCart/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
//#region src/components/booking/info/service2/Lists.tsx
const Lists = ({ onEdit, onChange }) => {
	var _state$service;
	const { state } = (0, react.useContext)(require_model.Context);
	const [params, setParams] = (0, react.useState)(require_status.defaultData);
	const { holderLists } = require_useSelectPet.default(state);
	(0, react.useEffect)(() => {
		const keys = require_utils.formatActiveKey(holderLists, params === null || params === void 0 ? void 0 : params.platform, !!state.bookingId);
		onChange({ activeCartId: keys }, "setActiveCartId");
		setParams(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, params), {}, { activeKey: keys }));
	}, [holderLists, params === null || params === void 0 ? void 0 : params.platform]);
	/**
	* @title: 更新商品数据
	* @description:
	* @param {any} newState
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-11-29 16:35
	*/
	const handleChange = (currentItem, type, other) => {
		if (state.disabledEdit || state.disableEventBookingEdit) return;
		let products = require_utils.updateServices(state, currentItem, type, other);
		if (type === "view") {
			var _window$openBookingEd, _window;
			let product = currentItem._origin;
			(_window$openBookingEd = (_window = window).openBookingEditModal) === null || _window$openBookingEd === void 0 || _window$openBookingEd.call(_window);
			onChange({
				editModal: true,
				cacheItem: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, product), {}, { new: 0 })
			});
			return onEdit === null || onEdit === void 0 ? void 0 : onEdit(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, product), {}, { new: 0 }));
		}
		onChange({
			editModal: false,
			value: products,
			edit: true,
			cacheItem: null
		});
	};
	/**
	* @title: 打开哪个折叠面板的keys
	* @description:
	* @param {any} key
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-09 16:06
	*/
	const handleActiveKey = (key) => {
		onChange({ activeCartId: key }, "setActiveCartId");
		setParams(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, params), {}, { activeKey: key }));
	};
	/**
	* @title: 折叠面板参数
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-05 15:22
	*/
	const CollapseParams = (0, react.useMemo)(() => {
		return {
			activeKey: params === null || params === void 0 ? void 0 : params.activeKey,
			bordered: false
		};
	}, [params === null || params === void 0 ? void 0 : params.activeKey]);
	/**
	* @title: 商品信息
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-09 16:07
	*/
	const productParams = (0, react.useMemo)(() => {
		return {
			hideAddBtn: state.isTerminalDayBookingPage,
			isShowNote: require_utils.isEventBooking(state),
			isShowPackageNote: false,
			holders: holderLists,
			isEdit: !!(state === null || state === void 0 ? void 0 : state.bookingId),
			disabledEdit: state === null || state === void 0 ? void 0 : state.disabledEdit,
			maxLength: require_utils.isEventBooking(state) ? 1 : 999
		};
	}, [holderLists, state === null || state === void 0 ? void 0 : state.bookingId]);
	return /* @__PURE__ */ react.default.createElement(require_Provider.CartContext.Provider, { value: { state } }, /* @__PURE__ */ react.default.createElement(require_index.default, {
		onChange: handleChange,
		onAddProduct: () => onChange({ addModal: true }),
		onActiveKey: handleActiveKey,
		collapseParams: CollapseParams,
		productParams: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, productParams), {}, { products: require_utils.formatProducts(state === null || state === void 0 || (_state$service = state.service) === null || _state$service === void 0 ? void 0 : _state$service.value, state) })
	}));
};
//#endregion
exports.default = Lists;
