const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_locales = require("../../../utils/locales.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_locales$1 = require("../locales.js");
const require_utilsByBooking = require("./utilsByBooking.js");
const require_utils = require("../utils.js");
const require_model = require("../info/model.js");
const require_index = require("../info/client/index.js");
const require_useEngineContext = require("../../../hooks/useEngineContext.js");
const require_serve = require("./serve.js");
const require_index$1 = require("./cartClientCard/index.js");
const require_index$2 = require("../components/tabPane/index.js");
const require_index$3 = require("../components/footer/index.js");
const require_index$4 = require("./service/index.js");
const require_index$5 = require("../info/pet/index.js");
const require_index$6 = require("../info/date/index.js");
const require_index$7 = require("../info/header/index.js");
const require_index$8 = require("../components/reloadResourceModal/index.js");
const require_index$9 = require("../info/notes/index.js");
const require_useCreateBookingPageHeader = require("../hooks/useCreateBookingPageHeader.js");
const require_index$10 = require("./service/contactInfoMode/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let ahooks = require("ahooks");
require("../info/index.less");
//#region src/components/booking/info2/index.tsx
const defaultModules = {
	client: 1,
	date: 1,
	service: 1,
	holder: 1,
	note: 1
};
_pisell_utils.locales.init(require_locales$1.default, require_locales.getLocale());
const Info = require_model.Provider((props) => {
	var _modal$state2, _modal$state3, _modal$state5, _modal$state6, _modal$state7;
	const { style, globalState, modules = defaultModules, slot } = props;
	const modal = (0, react.useContext)(require_model.Context);
	const context = require_useEngineContext.default();
	require_utils.request.setRequest(context.appHelper.utils.request);
	const params = (0, react.useMemo)(() => {
		var _modal$state;
		return ((_modal$state = modal.state) === null || _modal$state === void 0 || (_modal$state = _modal$state.bookingConfig) === null || _modal$state === void 0 || (_modal$state = _modal$state.config) === null || _modal$state === void 0 || (_modal$state = _modal$state.basic) === null || _modal$state === void 0 ? void 0 : _modal$state.appointment_subject) || {};
	}, [(_modal$state2 = modal.state) === null || _modal$state2 === void 0 || (_modal$state2 = _modal$state2.bookingConfig) === null || _modal$state2 === void 0 || (_modal$state2 = _modal$state2.config) === null || _modal$state2 === void 0 || (_modal$state2 = _modal$state2.basic) === null || _modal$state2 === void 0 ? void 0 : _modal$state2.appointment_subject]);
	const stateRef = (0, react.useRef)(globalState);
	stateRef.current = globalState;
	const { createHeader, isBookingCreatePage, isBookingCreatePageCreateMode } = require_useCreateBookingPageHeader.default(globalState);
	(0, react.useEffect)(() => {
		document.body.id = "body";
		if (props.setState) props.setState({ bookingFunctions: {
			formatResource: require_utilsByBooking.formatResource,
			getErrorList: require_utilsByBooking.getErrorList,
			sliceDayIntoFiveMinutes: require_utils.sliceDayIntoFiveMinutes,
			findNextDuration: require_utils.findNextDuration,
			flexibleObj: require_utils.flexibleObj,
			updateServiceDate: require_index$6.updateServiceDate
		} });
	}, []);
	(0, _pisell_materials.useToast)();
	(0, react.useMemo)(() => {
		var _context$appHelper, _context$appHelper$ge, _context$appHelper2, _context$appHelper2$i, _context$appHelper3;
		const isFranchisee = context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.businessUtils) === null || _context$appHelper === void 0 || (_context$appHelper$ge = _context$appHelper.getAppByModal) === null || _context$appHelper$ge === void 0 ? void 0 : _context$appHelper$ge.call(_context$appHelper, "franchisee");
		modal.dispatch({
			type: "setState",
			payload: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({ setGlobalState: props.setGlobalState }, globalState), {}, {
				isTerminal: context === null || context === void 0 || (_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 || (_context$appHelper2$i = _context$appHelper2.isTerminal) === null || _context$appHelper2$i === void 0 ? void 0 : _context$appHelper2$i.call(_context$appHelper2),
				isFranchisee,
				timezone: context === null || context === void 0 || (_context$appHelper3 = context.appHelper) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.utils) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.store) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.getState()) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.global) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.globalConfig) === null || _context$appHelper3 === void 0 ? void 0 : _context$appHelper3.timezone
			})
		});
	}, [globalState]);
	const dropdownProps = (0, react.useMemo)(() => {
		return { buttonProps: {
			icon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
				type: "pisell2-switch-horizontal-01",
				size: 24,
				style: { color: "#667085" }
			}),
			size: "default"
		} };
	}, [modal.state]);
	const header$1 = (0, react.useMemo)(() => {
		if ((globalState === null || globalState === void 0 ? void 0 : globalState.renderType) === "eventBooking") return _pisell_utils.locales.getText("pisell2.text.enroll.detail");
		return (globalState === null || globalState === void 0 ? void 0 : globalState.bookingId) ? /* @__PURE__ */ react.default.createElement(require_index$7.default, {
			state: modal.state,
			dispatch: modal.dispatch
		}) : /* @__PURE__ */ react.default.createElement("div", {
			className: "",
			style: { height: 0 }
		});
	}, [
		globalState === null || globalState === void 0 ? void 0 : globalState.bookingId,
		modal.state,
		modal.dispatch,
		globalState === null || globalState === void 0 ? void 0 : globalState.renderType
	]);
	const notes = (0, react.useMemo)(() => {
		if (!modules.note) return null;
		return (globalState === null || globalState === void 0 ? void 0 : globalState.bookingId) ? globalState.renderType === "eventBooking" ? /* @__PURE__ */ react.default.createElement(require_index$9.default, null) : null : null;
	}, [
		modules.note,
		globalState === null || globalState === void 0 ? void 0 : globalState.bookingId,
		globalState.render,
		(_modal$state3 = modal.state) === null || _modal$state3 === void 0 || (_modal$state3 = _modal$state3.notes) === null || _modal$state3 === void 0 ? void 0 : _modal$state3.orderNote
	]);
	const currentDate = (0, react.useMemo)(() => {
		var _modal$state4;
		if ((_modal$state4 = modal.state) === null || _modal$state4 === void 0 || (_modal$state4 = _modal$state4.date) === null || _modal$state4 === void 0 ? void 0 : _modal$state4.value) return modal.state.date.value.format("YYYY-MM-DD");
		return null;
	}, [(_modal$state5 = modal.state) === null || _modal$state5 === void 0 || (_modal$state5 = _modal$state5.date) === null || _modal$state5 === void 0 || (_modal$state5 = _modal$state5.value) === null || _modal$state5 === void 0 ? void 0 : _modal$state5.format("YYYY-MM-DD")]);
	/**
	* @title: 获取资源列表数据
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 13:38
	*/
	const getResourcesData = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
			let bookingResourceList = localStorage.getItem("bookingResourceList");
			let timeoutNumber = 0;
			if (bookingResourceList) {
				bookingResourceList = JSON.parse(bookingResourceList);
				if ((bookingResourceList === null || bookingResourceList === void 0 ? void 0 : bookingResourceList.date) === currentDate) {
					timeoutNumber = 200;
					modal.dispatch({
						type: "setService",
						payload: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, stateRef.current.service), {}, {
							resourcesOrigin: bookingResourceList.list || [],
							resourcesOriginMap: bookingResourceList.listMap
						})
					});
				}
			}
			return new Promise((resolve, reject) => {
				setTimeout(require_asyncToGenerator._asyncToGenerator(function* () {
					try {
						var _stateRef$current, _stateRef$current$map;
						let data = yield require_serve.getResourceList({ date: currentDate }, stateRef === null || stateRef === void 0 || (_stateRef$current = stateRef.current) === null || _stateRef$current === void 0 || (_stateRef$current = _stateRef$current.service) === null || _stateRef$current === void 0 || (_stateRef$current = _stateRef$current.value) === null || _stateRef$current === void 0 || (_stateRef$current$map = _stateRef$current.map) === null || _stateRef$current$map === void 0 ? void 0 : _stateRef$current$map.call(_stateRef$current, (item) => item === null || item === void 0 ? void 0 : item.booking_id));
						try {
							data.date = currentDate;
						} catch (error) {
							(0, _pisell_utils.sendWarningLog)({
								title: `设置资源失败`,
								content: [{
									key: "error",
									value: JSON.stringify({
										message: error === null || error === void 0 ? void 0 : error.message,
										stack: error === null || error === void 0 ? void 0 : error.stack,
										name: error === null || error === void 0 ? void 0 : error.name
									})
								}]
							});
						}
						try {
							data.date = currentDate;
						} catch (err) {}
						modal.dispatch({
							type: "setService",
							payload: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, stateRef.current.service), {}, {
								resourcesOrigin: data.list || [],
								resourcesOriginMap: data.listMap,
								reloadResourceModal: false
							})
						});
						resolve(data);
					} catch (error) {
						(0, _pisell_utils.sendWarningLog)({
							title: `获取资源失败`,
							content: [{
								key: "error",
								value: JSON.stringify({
									message: error === null || error === void 0 ? void 0 : error.message,
									stack: error === null || error === void 0 ? void 0 : error.stack,
									name: error === null || error === void 0 ? void 0 : error.name
								})
							}]
						});
						modal.dispatch({
							type: "setService",
							payload: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, stateRef.current.service), {}, { reloadResourceModal: true })
						});
						reject(error);
					}
				}), timeoutNumber);
			});
		});
		return function getResourcesData() {
			return _ref.apply(this, arguments);
		};
	}();
	(0, ahooks.useDebounceEffect)(() => {
		if (currentDate) getResourcesData();
	}, [currentDate], { wait: 300 });
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(require_index$8.default, {
		modal,
		onReload: getResourcesData,
		onCancel: () => {
			modal.dispatch({
				type: "setService",
				payload: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, stateRef.current.service), {}, { reloadResourceModal: false })
			});
		}
	}), !!modal.state.setGlobalState ? /* @__PURE__ */ react.default.createElement(require_index$2.default, {
		style: { height: "100%" },
		header: header$1,
		footer: /* @__PURE__ */ react.default.createElement(require_index$3.default, {
			state: modal.state,
			dispatch: modal.dispatch,
			source: "info"
		}),
		bodyClassName: (0, classnames.default)("booking-info-warp", {
			["create-booking-page-info-wrap"]: isBookingCreatePage,
			["create-booking-page-info-wrap-create"]: isBookingCreatePageCreateMode
		}),
		state: modal.state,
		dispatch: modal.dispatch,
		source: "info"
	}, /* @__PURE__ */ react.default.createElement("div", { className: "booking-info" }, createHeader, /* @__PURE__ */ react.default.createElement("div", { className: "booking-info-client-line" }, modules.client ? (globalState === null || globalState === void 0 ? void 0 : globalState.isBookingTicket2) ? /* @__PURE__ */ react.default.createElement("div", { style: {
		flex: 1,
		overflow: "hidden"
	} }, /* @__PURE__ */ react.default.createElement(require_index$1.default, { clientCardProps: { dropdown: dropdownProps } })) : /* @__PURE__ */ react.default.createElement(require_index.default, null) : null, (globalState === null || globalState === void 0 ? void 0 : globalState.isBookingTicket2) ? /* @__PURE__ */ react.default.createElement("div", {
		className: "booking-info-client-line-code",
		onClick: () => {
			var _globalState$onQrCode;
			globalState === null || globalState === void 0 || (_globalState$onQrCode = globalState.onQrCodeClick) === null || _globalState$onQrCode === void 0 || _globalState$onQrCode.call(globalState);
		}
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
		type: "pisell2-a-qr-code-02",
		style: {
			color: "#fff",
			fontSize: 42
		}
	})) : null), (modal === null || modal === void 0 || (_modal$state6 = modal.state) === null || _modal$state6 === void 0 || (_modal$state6 = _modal$state6.bookingConfig) === null || _modal$state6 === void 0 || (_modal$state6 = _modal$state6.config) === null || _modal$state6 === void 0 || (_modal$state6 = _modal$state6.cart_settings_tab) === null || _modal$state6 === void 0 || (_modal$state6 = _modal$state6.display_contact_info) === null || _modal$state6 === void 0 ? void 0 : _modal$state6.show_contact_info) === true ? /* @__PURE__ */ react.default.createElement(require_index$10.default, null) : null, modules.holder && !((_modal$state7 = modal.state) === null || _modal$state7 === void 0 ? void 0 : _modal$state7.disabledEdit) ? /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, params.type === "form" ? /* @__PURE__ */ react.default.createElement(require_index$5.default, null) : null) : null, modules.date ? /* @__PURE__ */ react.default.createElement(require_index$6.default, null) : null, /* @__PURE__ */ react.default.createElement(antd.Skeleton, {
		loading: globalState.loading,
		round: true,
		active: true,
		avatar: false,
		style: { paddingTop: 20 }
	}, modules.service ? /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, modal.state.date.value ? /* @__PURE__ */ react.default.createElement(require_index$4.default, null) : null) : null, notes, slot ? slot : null))) : null);
});
//#endregion
exports.default = Info;
