import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { Context } from "../model.js";
import useQuotation from "../../hooks/useQuotation.js";
import Info from "../service/addService/index.js";
import editService_default from "../service/editService/index.js";
import Lists from "./Lists.js";
import React, { createContext, useContext, useEffect, useRef } from "react";
createContext({});
const Service2Cart = ({ hideAdd, hideEdit }) => {
	const detailRef = useRef();
	const { state, dispatch } = useContext(Context);
	useEffect(() => {
		document.body.id = "body";
	}, []);
	/**
	* @title: 更新服务
	* @description:
	* @param {string} type
	* @param {any} payload
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-09 16:02
	*/
	const dispatchService = (type, payload) => {
		dispatch({
			type,
			payload: _objectSpread2({}, payload)
		});
	};
	const handleEdit = (cacheItem, type) => {
		setTimeout(() => {
			var _detailRef$current, _detailRef$current$in;
			(_detailRef$current = detailRef.current) === null || _detailRef$current === void 0 || (_detailRef$current$in = _detailRef$current.init) === null || _detailRef$current$in === void 0 || _detailRef$current$in.call(_detailRef$current, cacheItem, false, type === "edit_product");
		}, 100);
	};
	const { dom } = useQuotation(state, dispatch);
	return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-service-wrap" }, /* @__PURE__ */ React.createElement(Lists, {
		onEdit: handleEdit,
		onChange: (e, type) => dispatchService(type || "setService", e)
	}), !hideAdd && /* @__PURE__ */ React.createElement(Info, { onEdit: handleEdit })), !hideEdit && /* @__PURE__ */ React.createElement(editService_default, { ref: detailRef }), dom);
};
//#endregion
export { Service2Cart };
