import { Context } from "../model.js";
import useQuotation from "../../hooks/useQuotation.js";
import useClearCart from "../../hooks/useClearCart.js";
import Info from "./addService/index.js";
import editService_default from "./editService/index.js";
import ServiceList from "./serviceList/index.js";
import AddTimeModal from "./addTimeModal/index.js";
import React, { useContext, useEffect, useMemo, useRef } from "react";
import "./index.less";
//#region src/components/booking/info/service/index.tsx
const Service = () => {
	var _state$bookingConfig2;
	const { state, dispatch } = useContext(Context);
	const detailRef = useRef();
	useEffect(() => {
		document.body.id = "body";
	}, []);
	const appointment_card = 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.information_tab) === null || _state$bookingConfig === void 0 ? void 0 : _state$bookingConfig.appointment_card) || { quick_time: 1 };
	}, [state === null || state === void 0 || (_state$bookingConfig2 = state.bookingConfig) === null || _state$bookingConfig2 === void 0 || (_state$bookingConfig2 = _state$bookingConfig2.config) === null || _state$bookingConfig2 === void 0 ? void 0 : _state$bookingConfig2.information_tab]);
	const showAddTimeModal = useMemo(() => {
		if ((state === null || state === void 0 ? void 0 : state.renderType) === "eventBooking") return false;
		if (state === null || state === void 0 ? void 0 : state.disabledEdit) return false;
		if (appointment_card.quick_time !== 1) return false;
		return true;
	}, [state, appointment_card.quick_time]);
	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 clearCart = useClearCart(state, dispatch);
	const { dom } = useQuotation(state, dispatch);
	return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-service-wrap" }, clearCart, /* @__PURE__ */ React.createElement(ServiceList, { onEdit: handleEdit }), !state.isBookingCreatePage ? /* @__PURE__ */ React.createElement(Info, { onEdit: handleEdit }) : null), /* @__PURE__ */ React.createElement(editService_default, { ref: detailRef }), showAddTimeModal && /* @__PURE__ */ React.createElement(AddTimeModal, null), dom);
};
var service_default = React.memo(Service);
//#endregion
export { service_default as default };
