const require_runtime = require("../../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_mock = require("../../../mock.js");
const require_asyncToGenerator = require("../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_utils = require("../../service2/Group/utils.js");
const require_utils$1 = require("../addService/utils.js");
const require_utils$2 = require("../../service2/utils.js");
const require_utils$3 = require("../../../utils.js");
const require_utils$4 = require("../../utils.js");
const require_model = require("../../model.js");
const require_index = require("../../../components/drawer/index.js");
const require_useEngineContext = require("../../../../../hooks/useEngineContext.js");
const require_index$1 = require("../../../materiels/duration/index.js");
const require_index$2 = require("../like/index.js");
const require_index$3 = require("../../../components/collapsibleList/index.js");
const require_utils$5 = require("../../../components/collapsibleList/utils.js");
const require_index$4 = require("./EditTabs/index.js");
const require_useSelectPet = require("../../service2/hooks/useSelectPet.js");
const require_index$5 = require("./BookingList/index.js");
const require_index$6 = require("../serviceManager/index.js");
const require_index$7 = require("../../../materiels/holder/index.js");
const require_constants = require("./constants.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
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 ahooks = require("ahooks");
let _pisell_icon_es_Delete_wght300_24px = require("@pisell/icon/es/Delete_wght300_24px");
_pisell_icon_es_Delete_wght300_24px = require_runtime.__toESM(_pisell_icon_es_Delete_wght300_24px);
require("./index.less");
//#region src/components/booking/info/service/editService/index.tsx
let submitLock = false;
const Info = (_, ref) => {
	var _state$bookingConfig2, _state$service$cacheI4, _state$service$cacheI6, _state$service$cacheI7, _state$service4, _state$service6, _state$service8, _state$date, _state$date$format, _state$date2, _window$BaseMaterials, _state$service$cacheI13, _state$service10, _state$service$cacheI14, _state$bookingConfig4;
	const [form] = antd.Form.useForm();
	const context = require_useEngineContext.default();
	const useTotal = antd.Form.useWatch("total", form);
	const useLikeStatus = antd.Form.useWatch("like_status", form);
	const useResource = antd.Form.useWatch("resource", form);
	const useStartTime = antd.Form.useWatch("start_time", form);
	const useDuration = antd.Form.useWatch("duration", form);
	const useStartDate = antd.Form.useWatch("start_date", form);
	const useEndDate = antd.Form.useWatch("end_date", form);
	const [resourceLoading, setResourceLoading] = (0, react.useState)(false);
	const { state, dispatch } = (0, react.useContext)(require_model.Context);
	const [selectOpen, setSelectOpen] = (0, react.useState)();
	const { holderLists } = require_useSelectPet.default(state);
	const isChangeTotal = (0, react.useRef)(false);
	const { editBookingData, editBooking } = require_index$6.useService({
		state,
		dispatch
	});
	const [currentTab, setCurrentTab] = (0, react.useState)("batch_edit");
	const isDayBookingMode = (0, react.useMemo)(() => {
		return require_utils$2.isDayBooking(state);
	}, [state === null || state === void 0 ? void 0 : state.renderType]);
	const isDaysBookingMode = (0, react.useMemo)(() => {
		return require_utils$2.isDaysBooking(state);
	}, [state === null || state === void 0 ? void 0 : state.renderType]);
	const isEventBookingMode = (0, react.useMemo)(() => {
		return require_utils$2.isEventBooking(state);
	}, [state === null || state === void 0 ? void 0 : state.renderType]);
	const getCurrentCacheItem = (_cacheItem) => {
		var _state$service;
		let values = form.getFieldsValue();
		let _item = _cacheItem || (state === null || state === void 0 || (_state$service = state.service) === null || _state$service === void 0 ? void 0 : _state$service.cacheItem);
		return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, _item), {}, { _extend: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, _item === null || _item === void 0 ? void 0 : _item._extend), values) });
	};
	/**
	* @title: 当前的资源
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:06
	*/
	const currentResource = (0, react.useMemo)(() => {
		return state.service.resources.find((d) => d.form_record_id == useResource) || {};
	}, [useResource, state.service.resources]);
	/**
	* @title: 持续时长组件的props
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-02-23 09:59
	*/
	const durationProps = (0, react.useMemo)(() => {
		var _state$bookingConfig;
		return require_utils$1.getDurationProps({
			cacheItem: getCurrentCacheItem(),
			useStartTime,
			currentResource,
			slice: (_state$bookingConfig = state.bookingConfig) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.config) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.basic) === null || _state$bookingConfig === void 0 ? void 0 : _state$bookingConfig.service_time
		});
	}, [
		currentResource,
		state.service.cacheItem,
		useStartTime,
		useResource,
		(_state$bookingConfig2 = state.bookingConfig) === null || _state$bookingConfig2 === void 0 || (_state$bookingConfig2 = _state$bookingConfig2.config) === null || _state$bookingConfig2 === void 0 || (_state$bookingConfig2 = _state$bookingConfig2.basic) === null || _state$bookingConfig2 === void 0 ? void 0 : _state$bookingConfig2.service_time
	]);
	/**
	* @title: 灵活时长选项
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-02-23 10:10
	*/
	const flexibleOption = (0, react.useMemo)(() => {
		return require_utils$1.getFlexibleOption({ durationProps });
	}, [durationProps, _pisell_utils.locales.locale]);
	/**
	* @title: 时间切片
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 13:37
	*/
	const timeObj = (0, react.useMemo)(() => {
		return require_utils$1.getTimeObj({
			durationProps,
			useStartTime,
			currentResource,
			state,
			useDuration
		});
	}, [
		state,
		_pisell_utils.locales.locale,
		useDuration,
		useStartTime,
		flexibleOption
	]);
	(0, react.useEffect)(() => {
		try {
			if (useDuration.indexOf("flexible_") == 0) {
				if (flexibleOption) form.setFieldsValue({ duration: flexibleOption.value });
			}
		} catch (err) {}
	}, [useDuration, flexibleOption]);
	/**
	* @title: 获取资源列表
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 13:38
	*/
	const getResources = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* (cacheItem, open) {
			console.log("getResources2");
			try {
				let _list = state.service.resourcesOrigin || [];
				const _cacheItem = cacheItem || getCurrentCacheItem();
				let autoClose = _cacheItem === null || _cacheItem === void 0 ? void 0 : _cacheItem.autoClose;
				if (!_cacheItem._extend) return;
				dispatch({
					type: "setService",
					payload: { resources: require_utils$1.formatResources({
						cacheItem: _cacheItem,
						resourcesOrigin: _list,
						isDay: isDayBookingMode
					}) }
				});
				if (_cacheItem.new) if (autoClose) setTimeout(() => {
					form.submit();
				}, 200);
				else setTimeout(() => {
					if (selectOpen === void 0 || open) setSelectOpen(true);
				}, 500);
			} catch (err) {}
		});
		return function getResources(_x, _x2) {
			return _ref.apply(this, arguments);
		};
	}();
	/**
	* @title: 删除服务商品
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 13:59
	*/
	const handleDeleteProduct = (0, ahooks.useMemoizedFn)(() => {
		var _state$service$cacheI, _window$closeBookingE, _window;
		if (state.channelDisabledEdit) return;
		let _list = [...state.service.value];
		let _id = (_state$service$cacheI = state.service.cacheItem) === null || _state$service$cacheI === void 0 ? void 0 : _state$service$cacheI._id;
		if (require_utils.isGroupBooking(_id)) _list = require_utils.filterItemByGroupId(_id, _list);
		else _list = _list.filter((d) => d._id !== _id);
		(_window$closeBookingE = (_window = window).closeBookingEditModal) === null || _window$closeBookingE === void 0 || _window$closeBookingE.call(_window);
		dispatch({
			type: "setService",
			payload: {
				editModal: false,
				value: _list,
				edit: true,
				cacheItem: null
			}
		});
	});
	/**
	* @title: 渲染下拉框
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:02
	*/
	const renderOptions = (0, react.useCallback)((array, value = "value", label = "label", type) => {
		return array.map((d) => {
			let props = {};
			if (type === "resource") props.labelText = d.labelText;
			return /* @__PURE__ */ react.default.createElement(antd.Select.Option, require_objectSpread2._objectSpread2({
				value: d[value],
				key: d[value]
			}, props), d[label]);
		});
	}, []);
	/**
	* @title: 点赞资源
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:02
	*/
	const handleLikeResource = (0, ahooks.useMemoizedFn)((status) => {
		form.setFieldsValue({ like_status: status });
	});
	/**
	* @title: 获取错误信息
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:02
	*/
	const getErrorMsg = () => {
		let item = state.service.resources.find((d) => d.form_record_id == useResource);
		if (item) {
			var _item$_extend$usableT;
			if (((_item$_extend$usableT = item._extend.usableTime) === null || _item$_extend$usableT === void 0 || (_item$_extend$usableT = _item$_extend$usableT._extend) === null || _item$_extend$usableT === void 0 ? void 0 : _item$_extend$usableT.isMaxLimitRange) === "unknown") {}
		}
	};
	/**
	* @title: 计算折扣
	* @description: 仅是文案展示
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:03
	*/
	const getDiscount = () => {
		var _state$service$cacheI2;
		console.log("折扣内", state.service.cacheItem);
		let oPrice = Number(((_state$service$cacheI2 = state.service.cacheItem) === null || _state$service$cacheI2 === void 0 ? void 0 : _state$service$cacheI2._extend.origin_total) || 0);
		let cPrice = Number(useTotal || 0);
		let discount = "";
		if (cPrice === oPrice) discount = _pisell_utils.locales.getText("pisell2.text.status.no-discount");
		else {
			discount = `${_pisell_utils.locales.getText("pisell2.text.status.manual")} `;
			if (cPrice < oPrice) discount += (0, _pisell_utils.formatAmount)(cPrice - oPrice, 2, state.amountSymbol) + "";
			else discount += "+" + (0, _pisell_utils.formatAmount)(cPrice - oPrice, 2, state.amountSymbol);
		}
		form.setFieldsValue({ discount });
	};
	/**
	* @title: 提交,
	* @description:
	* @param {any} values
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:04
	*/
	const onFinish = (0, ahooks.useMemoizedFn)(function() {
		var _ref2 = require_asyncToGenerator._asyncToGenerator(function* (values) {
			if (submitLock) return;
			submitLock = true;
			setTimeout(() => {
				submitLock = false;
			}, 1500);
			const data = yield editBookingData({ changeValues: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, values), {}, { errorList }) });
			if (isChangeTotal.current) delete data.discount_list;
			yield editBooking({ booking: data });
		});
		return function(_x3) {
			return _ref2.apply(this, arguments);
		};
	}());
	const setEditData = (0, ahooks.useMemoizedFn)((_cacheItem, open, openProductDetail) => {
		setCurrentTab("batch_edit");
		isChangeTotal.current = false;
		let cacheItem = _cacheItem || state.service.cacheItem;
		let values = cacheItem._extend;
		values = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, values), {}, { discount_reason: (values === null || values === void 0 ? void 0 : values.discount_reason) || "" });
		form.setFieldsValue(values);
		if (openProductDetail) setTimeout(() => {
			handleEdit({});
		}, 100);
		if (!isEventBookingMode) getResources(cacheItem, open);
	});
	/**
	* @title: 是否显示折扣原因
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:06
	*/
	const isReason = (0, react.useMemo)(() => {
		var _state$service$cacheI3;
		let oPrice = Number(((_state$service$cacheI3 = state.service.cacheItem) === null || _state$service$cacheI3 === void 0 ? void 0 : _state$service$cacheI3._extend.origin_total) || 0);
		return Number(useTotal || 0) !== oPrice;
	}, [useTotal, (_state$service$cacheI4 = state.service.cacheItem) === null || _state$service$cacheI4 === void 0 || (_state$service$cacheI4 = _state$service$cacheI4._extend) === null || _state$service$cacheI4 === void 0 ? void 0 : _state$service$cacheI4.origin_total]);
	/**
	* @title: 错误信息列表
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:06
	*/
	const errorList = (0, react.useMemo)(() => {
		return require_utils$3.getErrorList(currentResource, getCurrentCacheItem(), isDayBookingMode);
	}, [
		currentResource,
		useDuration,
		useStartTime
	]);
	/**
	* @title: 开始时间 和 服务时间 发生变化时,重新计算资源
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:07
	*/
	(0, ahooks.useUpdateEffect)(() => {
		var _state$service$cacheI5;
		if (state.service.cacheItem && !((_state$service$cacheI5 = state.service.cacheItem) === null || _state$service$cacheI5 === void 0 ? void 0 : _state$service$cacheI5.autoClose)) {
			if (useStartTime && useDuration && !isEventBookingMode) getResources();
		}
	}, [
		useStartTime,
		useDuration,
		state.renderType,
		state.service.resourcesOrigin,
		(_state$service$cacheI6 = state.service.cacheItem) === null || _state$service$cacheI6 === void 0 ? void 0 : _state$service$cacheI6.autoClose
	]);
	/**
	* @title: 是否在terminal上打开预约
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-04 19:02
	*/
	const isTerminalBooking = (0, react.useMemo)(() => {
		return state.isBookingCreatePage || state.isTerminalDayBookingPage;
	}, [state.isBookingCreatePage, state.isTerminalDayBookingPage]);
	(0, react.useEffect)(() => {
		if (isTerminalBooking && state.service.editModal) setEditData(null, true);
	}, [state.service.editModal, isTerminalBooking]);
	/**
	* @title: 资源 时间 发生变化时, 重新计算错误信息
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:07
	*/
	(0, react.useEffect)(() => {
		getErrorMsg();
	}, [
		useResource,
		useStartTime,
		useDuration,
		useStartDate,
		useEndDate
	]);
	/**
	* @title: 价格发生变化,重新计算折扣
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:08
	*/
	(0, react.useEffect)(() => {
		getDiscount();
	}, [useTotal, (_state$service$cacheI7 = state.service.cacheItem) === null || _state$service$cacheI7 === void 0 || (_state$service$cacheI7 = _state$service$cacheI7._extend) === null || _state$service$cacheI7 === void 0 ? void 0 : _state$service$cacheI7.origin_total]);
	const isDiscount = (0, react.useMemo)(() => {
		var _state$service2, _state$service3;
		if (!((_state$service2 = state.service) === null || _state$service2 === void 0 ? void 0 : _state$service2.cacheItem)) return false;
		return useTotal != ((_state$service3 = state.service) === null || _state$service3 === void 0 || (_state$service3 = _state$service3.cacheItem) === null || _state$service3 === void 0 ? void 0 : _state$service3._extend.origin_total);
	}, [useTotal, (_state$service4 = state.service) === null || _state$service4 === void 0 || (_state$service4 = _state$service4.cacheItem) === null || _state$service4 === void 0 ? void 0 : _state$service4._extend.origin_total]);
	(0, react.useEffect)(() => {
		if (useResource === 0) handleLikeResource("common");
	}, [useResource]);
	const bundles = (0, react.useMemo)(() => {
		var _state$service5;
		return ((_state$service5 = state.service) === null || _state$service5 === void 0 || (_state$service5 = _state$service5.cacheItem) === null || _state$service5 === void 0 || (_state$service5 = _state$service5._extend) === null || _state$service5 === void 0 || (_state$service5 = _state$service5.other) === null || _state$service5 === void 0 ? void 0 : _state$service5.bundle) || [];
	}, [(_state$service6 = state.service) === null || _state$service6 === void 0 || (_state$service6 = _state$service6.cacheItem) === null || _state$service6 === void 0 || (_state$service6 = _state$service6._extend) === null || _state$service6 === void 0 || (_state$service6 = _state$service6.other) === null || _state$service6 === void 0 ? void 0 : _state$service6.bundle]);
	const multiDayPrices = (0, react.useMemo)(() => {
		var _state$service7;
		return Object.entries(require_utils$4.getMultiDayPrices(((_state$service7 = state.service) === null || _state$service7 === void 0 || (_state$service7 = _state$service7.cacheItem) === null || _state$service7 === void 0 || (_state$service7 = _state$service7._extend) === null || _state$service7 === void 0 ? void 0 : _state$service7.multi_day) || [])).map(([key, value]) => {
			return {
				key,
				value
			};
		});
	}, [(_state$service8 = state.service) === null || _state$service8 === void 0 || (_state$service8 = _state$service8.cacheItem) === null || _state$service8 === void 0 || (_state$service8 = _state$service8._extend) === null || _state$service8 === void 0 ? void 0 : _state$service8.multi_day]);
	/**
	* @title: 获取资源列表数据
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 13:38
	*/
	const getResourcesData = function() {
		var _ref3 = require_asyncToGenerator._asyncToGenerator(function* () {
			setResourceLoading(true);
			try {
				var _context$appHelper$ut, _context$appHelper$ut2;
				let params = {};
				if (isDayBookingMode) {
					const format = "YYYY-MM-DD HH:mm";
					const { startDateTime, endDateTime } = require_utils$2.formatDayTime({
						startDate: useStartDate || state.date.value,
						endDate: useEndDate || state.date.end_date
					});
					if ((0, dayjs.default)(startDateTime).isAfter((0, dayjs.default)(endDateTime))) return;
					params.check_time = {
						start_time: (0, dayjs.default)(startDateTime).format(format),
						end_time: (0, dayjs.default)(endDateTime).format(format)
					};
				} else params.with_date_times = state.date.value.format("YYYY-MM-DD");
				const codes = require_constants.getIsPartyRoomResourceShop((_context$appHelper$ut = context.appHelper.utils.store) === null || _context$appHelper$ut === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut.getState) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.call(_context$appHelper$ut)) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.global) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.globalConfig) === null || _context$appHelper$ut2 === void 0 ? void 0 : _context$appHelper$ut2.id) ? [
					"resources",
					"therapist",
					"table",
					"party_room"
				] : [
					"resources",
					"therapist",
					"table"
				];
				let data = yield state.apis.getResources(require_objectSpread2._objectSpread2({
					skip: 1,
					num: 1e3,
					codes,
					_config: { abort: true }
				}, params));
				dispatch({
					type: "setService",
					payload: { resourcesOrigin: [require_mock.getNoResource()].concat((data === null || data === void 0 ? void 0 : data.list) || []) }
				});
			} catch (err) {
				console.log(err, "err");
			}
			setResourceLoading(false);
		});
		return function getResourcesData() {
			return _ref3.apply(this, arguments);
		};
	}();
	(0, react.useEffect)(() => {
		if (isEventBookingMode) return;
		setTimeout(() => {
			getResourcesData();
		}, 20);
	}, [
		(_state$date = state.date) === null || _state$date === void 0 || (_state$date = _state$date.value) === null || _state$date === void 0 || (_state$date$format = _state$date.format) === null || _state$date$format === void 0 ? void 0 : _state$date$format.call(_state$date, "YYYY-MM-DD"),
		(_state$date2 = state.date) === null || _state$date2 === void 0 ? void 0 : _state$date2.end_date,
		useStartDate,
		useEndDate,
		isEventBookingMode
	]);
	/**
	* @title: 编辑商品
	* @description:
	* @param {any} e
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-08-28 17:08
	*/
	const handleEdit = (0, ahooks.useMemoizedFn)((e) => {
		var _item$_extend6, _state$client;
		const item = state.service.cacheItem;
		let values = form.getFieldsValue();
		let dayValue = {};
		if (isDayBookingMode) {
			var _item$_extend, _item$_extend2;
			const option = (_item$_extend = item._extend) === null || _item$_extend === void 0 || (_item$_extend = _item$_extend.other) === null || _item$_extend === void 0 || (_item$_extend = _item$_extend.option) === null || _item$_extend === void 0 ? void 0 : _item$_extend.map((o) => {
				return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, o), {}, { option_group_item_id: o.product_option_item_id });
			});
			dayValue.product_variant = ((_item$_extend2 = item._extend) === null || _item$_extend2 === void 0 || (_item$_extend2 = _item$_extend2.other) === null || _item$_extend2 === void 0 ? void 0 : _item$_extend2.product_variant_id) || 0;
			dayValue.product_option = option || [];
		}
		const isSession = require_utils$3.isSessionProduct(item);
		const sessionValue = {};
		if (isSession) {
			var _item$_extend3, _item$_extend4, _item$_extend5;
			sessionValue.startEndTime = {
				startDate: item === null || item === void 0 || (_item$_extend3 = item._extend) === null || _item$_extend3 === void 0 ? void 0 : _item$_extend3.start_date,
				endDate: item === null || item === void 0 || (_item$_extend4 = item._extend) === null || _item$_extend4 === void 0 ? void 0 : _item$_extend4.end_date,
				duration: item === null || item === void 0 || (_item$_extend5 = item._extend) === null || _item$_extend5 === void 0 ? void 0 : _item$_extend5.duration
			};
		}
		state.action({
			type: "pisell1.handleOpenProductModal",
			data: {
				id: item.id,
				date: state.date.value.format("YYYY-MM-DD"),
				showConfig: {
					option: isDayBookingMode ? true : false,
					session: isSession,
					variant: isDayBookingMode ? true : false,
					package: true
				},
				value: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, ((_item$_extend6 = item._extend) === null || _item$_extend6 === void 0 ? void 0 : _item$_extend6.other) || {}), dayValue), sessionValue),
				isOS: isSession,
				customer_id: (_state$client = state.client) === null || _state$client === void 0 || (_state$client = _state$client.value) === null || _state$client === void 0 ? void 0 : _state$client.id
			},
			callback: function() {
				var _ref4 = require_asyncToGenerator._asyncToGenerator(function* (e, extension_type, detail) {
					var _cacheItem$_extend;
					const _detail = detail || item;
					const other = JSON.parse(JSON.stringify(e));
					other.session = e.session;
					let cacheItem = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), _detail), {}, {
						product_id: item.id,
						_id: item === null || item === void 0 ? void 0 : item._id,
						_key: e.key,
						_extend: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item._extend), values), {}, { other }),
						new: 0
					});
					let _total = require_utils$3.getProductTotalPrice(cacheItem);
					if (cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend = cacheItem._extend) === null || _cacheItem$_extend === void 0 || (_cacheItem$_extend = _cacheItem$_extend.other) === null || _cacheItem$_extend === void 0 ? void 0 : _cacheItem$_extend.product_variant_id) {
						var _cacheItem$_extend2;
						cacheItem._extend.price = Number((_cacheItem$_extend2 = cacheItem._extend) === null || _cacheItem$_extend2 === void 0 || (_cacheItem$_extend2 = _cacheItem$_extend2.other) === null || _cacheItem$_extend2 === void 0 ? void 0 : _cacheItem$_extend2.price);
					}
					const sessionDetail = require_utils$4.editSessionProduct(cacheItem, e.session);
					cacheItem._extend.total = _total;
					cacheItem._extend.origin_total = _total;
					dispatch({
						type: "setService",
						payload: { cacheItem }
					});
					if (isDaysBookingMode) setTimeout(() => {
						updateMultiDay({
							start_date: values.start_date,
							end_date: values.end_date
						});
					}, 100);
					else form.setFieldsValue(require_objectSpread2._objectSpread2({ total: _total }, require_utils$3.isSessionProduct(cacheItem) && sessionDetail ? {
						start_time: sessionDetail.start_time,
						duration: sessionDetail.duration
					} : {}));
				});
				return function callback(_x4, _x5, _x6) {
					return _ref4.apply(this, arguments);
				};
			}()
		});
	});
	/**
	* @title: 更换商品
	* @description:
	* @param {any} e
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-08-28 17:10
	*/
	const handleChange = (0, ahooks.useMemoizedFn)((e) => {
		if (state.channelDisabledEdit) return;
		dispatch({
			type: "setService",
			payload: {
				addModal: true,
				editModal: true,
				changeService: true
			}
		});
	});
	(0, react.useImperativeHandle)(ref, () => {
		return { init: setEditData };
	});
	const SelectTime = (_window$BaseMaterials = window.BaseMaterials) === null || _window$BaseMaterials === void 0 ? void 0 : _window$BaseMaterials.SelectTime;
	/**
	* @title: 日期组件
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-11-30 22:22
	*/
	const DateCom = (position) => {
		return /* @__PURE__ */ react.default.createElement(antd.DatePicker, {
			className: "pisell-lowcode__booking-service-select-date",
			disabledDate: (current) => require_utils$2.disabledDate(current, position, useStartDate),
			size: "large",
			style: { width: "100%" },
			format: state.locale === "en" ? "DD/MM/YYYY" : "YYYY-MM-DD"
		});
	};
	/**
	* @title: 更新报价单价格
	* @description:
	* @param {any} param1
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-29 23:17
	*/
	const updateMultiDay = function() {
		var _ref5 = require_asyncToGenerator._asyncToGenerator(function* ({ start_date, end_date, duration }) {
			const cacheItem = yield require_utils$1.getMultiDay({
				start_date,
				end_date,
				state,
				cacheItem: getCurrentCacheItem()
			});
			if (duration !== void 0) cacheItem._extend.duration = duration;
			cacheItem._extend.items = require_utils.createBookingItemsByGroup(cacheItem);
			cacheItem._extend = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, cacheItem._extend), require_utils.getGroupTotalPrice(cacheItem._extend.items));
			dispatch({
				type: "setService",
				payload: { cacheItem }
			});
			let fieldsValues = { total: cacheItem._extend.total };
			form.setFieldsValue(fieldsValues);
		});
		return function updateMultiDay(_x7) {
			return _ref5.apply(this, arguments);
		};
	}();
	/**
	* @title: 表单更新
	* @description:
	* @param {any} changedValues
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-04 14:39
	*/
	const onValuesChange = (changedValues) => {
		if (isDayBookingMode) {
			if (changedValues === null || changedValues === void 0 ? void 0 : changedValues.duration) {
				const end_date = (0, dayjs.default)(useStartDate).add(changedValues === null || changedValues === void 0 ? void 0 : changedValues.duration, "day");
				form.setFieldsValue({ end_date });
				return updateMultiDay({
					start_date: useStartDate,
					end_date,
					duration: changedValues === null || changedValues === void 0 ? void 0 : changedValues.duration
				});
			}
			if (changedValues === null || changedValues === void 0 ? void 0 : changedValues.start_date) {
				const startDate = (0, dayjs.default)(changedValues === null || changedValues === void 0 ? void 0 : changedValues.start_date);
				const endDate = (0, dayjs.default)(useEndDate);
				if (startDate.isAfter(endDate)) return form.setFieldsValue({
					duration: void 0,
					end_date: void 0
				});
			}
			if ((changedValues === null || changedValues === void 0 ? void 0 : changedValues.start_date) || (changedValues === null || changedValues === void 0 ? void 0 : changedValues.end_date)) {
				const duration = require_utils$3.getDays(getCurrentCacheItem(), "days");
				updateMultiDay({
					start_date: (changedValues === null || changedValues === void 0 ? void 0 : changedValues.start_date) || useStartDate,
					end_date: (changedValues === null || changedValues === void 0 ? void 0 : changedValues.end_date) || useEndDate,
					duration
				});
				return form.setFieldsValue({ duration });
			}
		}
	};
	/**
	* @title: 是否显示资源和时长
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-09 15:59
	*/
	const showResource = (0, react.useMemo)(() => {
		if (isEventBookingMode) return false;
		if (isDayBookingMode) return require_utils$2.isDayBookingProduct(state.service.cacheItem, state);
		return true;
	}, [state.service.cacheItem, state.renderType]);
	const items = (0, react.useMemo)(() => {
		var _getCurrentCacheItem;
		return ((_getCurrentCacheItem = getCurrentCacheItem()) === null || _getCurrentCacheItem === void 0 || (_getCurrentCacheItem = _getCurrentCacheItem._extend) === null || _getCurrentCacheItem === void 0 ? void 0 : _getCurrentCacheItem.items) || [];
	}, [
		getCurrentCacheItem(),
		state.service.cacheItem,
		useLikeStatus,
		currentResource,
		useTotal
	]);
	const isEditGroup = (0, react.useMemo)(() => {
		return items.length;
	}, [items]);
	const handleTotalChange = (number) => {
		isChangeTotal.current = true;
	};
	return (0, react.useMemo)(() => {
		var _state$service$cacheI8, _state$service9, _state$service$cacheI9, _state$service$cacheI10, _state$service$cacheI11, _state$service$cacheI12, _state$bookingConfig3;
		return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(require_index.default, {
			titleNoWrap: true,
			zIndex: state.service.changeService ? 999 : 1e3,
			forceRender: true,
			open: state.service.editModal && !((_state$service$cacheI8 = state.service.cacheItem) === null || _state$service$cacheI8 === void 0 ? void 0 : _state$service$cacheI8.autoClose),
			title: isDayBookingMode ? _pisell_utils.locales.getText("pisell2.text.edit-select-service") : _pisell_utils.locales.getText("pisell2.text.edit-service"),
			onClose: () => {
				var _window$closeBookingE2, _window2;
				(_window$closeBookingE2 = (_window2 = window).closeBookingEditModal) === null || _window$closeBookingE2 === void 0 || _window$closeBookingE2.call(_window2);
				dispatch({
					type: "setService",
					payload: {
						editModal: false,
						cacheItem: null,
						changeService: false
					}
				});
			}
		}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__booking-service-body-edit" }, isEditGroup ? /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(require_index$4.default, {
			value: currentTab,
			onChange: (e) => {
				console.log(e);
				setCurrentTab(e);
			}
		}), /* @__PURE__ */ react.default.createElement("div", {
			className: "",
			style: { display: currentTab === "booking_list" ? "block" : "none" }
		}, /* @__PURE__ */ react.default.createElement(require_index$5.default, { items }))) : null, /* @__PURE__ */ react.default.createElement("div", {
			className: "",
			style: { display: currentTab === "batch_edit" ? "block" : "none" }
		}, /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(_pisell_materials.Page, null, /* @__PURE__ */ react.default.createElement(antd.Form, {
			layout: "vertical",
			form,
			onFinish,
			onValuesChange
		}, /* @__PURE__ */ react.default.createElement(antd.Row, {
			style: { width: "100%" },
			gutter: [16, 0]
		}, /* @__PURE__ */ react.default.createElement(antd.Col, { span: 24 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, { name: "product_name" }, /* @__PURE__ */ react.default.createElement("div", { className: "current-service-info" }, /* @__PURE__ */ react.default.createElement("div", { className: "current-service-info-name-wrap" }, /* @__PURE__ */ react.default.createElement("div", { className: "current-service-info-name" }, ((_state$service9 = state.service) === null || _state$service9 === void 0 || (_state$service9 = _state$service9.cacheItem) === null || _state$service9 === void 0 || (_state$service9 = _state$service9._extend) === null || _state$service9 === void 0 ? void 0 : _state$service9.product_name) || "-"), /* @__PURE__ */ react.default.createElement(antd.Button, { onClick: handleEdit }, _pisell_utils.locales.getText("pisell2.text.edit")), !isTerminalBooking && /* @__PURE__ */ react.default.createElement(antd.Button, { onClick: handleChange }, _pisell_utils.locales.getText("pisell2.text.change"))), /* @__PURE__ */ react.default.createElement(require_index$3.default, {
			style: { marginTop: bundles.length ? "8px" : 0 },
			list: bundles,
			renderItem: (item) => require_utils$5.renderBundles(item, state.amountSymbol)
		})))), /* @__PURE__ */ react.default.createElement(antd.Col, { span: 24 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			label: _pisell_utils.locales.getText("pisell2.text.price"),
			name: "total",
			rules: [{ required: true }],
			extra: useTotal !== ((_state$service$cacheI9 = state.service.cacheItem) === null || _state$service$cacheI9 === void 0 || (_state$service$cacheI9 = _state$service$cacheI9._extend) === null || _state$service$cacheI9 === void 0 ? void 0 : _state$service$cacheI9.origin_total) && _pisell_utils.locales.getText("page.booking.text.price-extra")((0, _pisell_utils.formatAmount)((_state$service$cacheI10 = state.service.cacheItem) === null || _state$service$cacheI10 === void 0 || (_state$service$cacheI10 = _state$service$cacheI10._extend) === null || _state$service$cacheI10 === void 0 ? void 0 : _state$service$cacheI10.origin_total, 2, state.amountSymbol), (0, _pisell_utils.formatAmount)(useTotal, 2, state.amountSymbol))
		}, /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellAdjustPriceInputNumber, {
			style: { width: "100%" },
			min: 0,
			precision: 2,
			onChange: handleTotalChange,
			prefix: state.amountSymbol,
			disabled: state.channelDisabledEdit,
			originValue: ((_state$service$cacheI11 = state.service.cacheItem) === null || _state$service$cacheI11 === void 0 || (_state$service$cacheI11 = _state$service$cacheI11._extend) === null || _state$service$cacheI11 === void 0 ? void 0 : _state$service$cacheI11.origin_total) || 0,
			placeholder: ((_state$service$cacheI12 = state.service.cacheItem) === null || _state$service$cacheI12 === void 0 || (_state$service$cacheI12 = _state$service$cacheI12._extend) === null || _state$service$cacheI12 === void 0 ? void 0 : _state$service$cacheI12.origin_total) || "0"
		}))), isReason ? /* @__PURE__ */ react.default.createElement(antd.Col, { span: 24 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			label: _pisell_utils.locales.getText("pisell2.text.discount-reason"),
			name: "discount_reason"
		}, /* @__PURE__ */ react.default.createElement(antd.Input.TextArea, { size: "large" }))) : null, showResource && /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(antd.Col, { span: 12 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			label: _pisell_utils.locales.getText(isDayBookingMode ? "pisell2.text.start_date" : "pisell2.text.start_time"),
			name: isDayBookingMode ? "start_date" : "start_time",
			rules: [{ required: true }]
		}, isDayBookingMode ? DateCom("start") : SelectTime ? /* @__PURE__ */ react.default.createElement(SelectTime, {
			slice: (_state$bookingConfig3 = state.bookingConfig) === null || _state$bookingConfig3 === void 0 || (_state$bookingConfig3 = _state$bookingConfig3.config) === null || _state$bookingConfig3 === void 0 || (_state$bookingConfig3 = _state$bookingConfig3.basic) === null || _state$bookingConfig3 === void 0 || (_state$bookingConfig3 = _state$bookingConfig3.service_time) === null || _state$bookingConfig3 === void 0 ? void 0 : _state$bookingConfig3.value,
			timePickerProps: { style: { width: "100%" } },
			timeProps: { style: { zoom: .8 } }
		}) : null)), isDayBookingMode ? /* @__PURE__ */ react.default.createElement(antd.Col, { span: 12 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			label: _pisell_utils.locales.getText(isDayBookingMode ? "pisell2.text.end_date" : "pisell2.text.end_time"),
			name: "end_date",
			rules: [{ required: true }]
		}, DateCom("end"))) : null, /* @__PURE__ */ react.default.createElement(antd.Col, { span: 12 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			label: _pisell_utils.locales.getText("pisell2.text.duration"),
			name: "duration",
			rules: [{ required: true }]
		}, /* @__PURE__ */ react.default.createElement(require_index$1.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, durationProps), {}, { timeObj })))), isDayBookingMode && (holderLists === null || holderLists === void 0 ? void 0 : holderLists.length) > 0 ? /* @__PURE__ */ react.default.createElement(antd.Col, { span: isDayBookingMode ? 12 : 24 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			label: _pisell_utils.locales.getText("pisell2.text.holder"),
			name: "holder_id",
			rules: [{ required: isDayBookingMode }]
		}, /* @__PURE__ */ react.default.createElement(require_index$7.default, { size: "large" }))) : null, /* @__PURE__ */ react.default.createElement(antd.Col, { span: 24 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			required: true,
			label: _pisell_utils.locales.getText("pisell2.text.resource")
		}, /* @__PURE__ */ react.default.createElement("div", { className: "resource-col" }, /* @__PURE__ */ react.default.createElement(antd.Button, {
			className: "resource-col-like-wrap",
			disabled: !useResource,
			onClick: () => {
				handleLikeResource(useLikeStatus === "like" ? "common" : "like");
			}
		}, /* @__PURE__ */ react.default.createElement(require_index$2.default, { status: useLikeStatus })), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			name: "resource",
			noStyle: true,
			rules: [{ required: true }]
		}, /* @__PURE__ */ react.default.createElement(antd.Select, {
			loading: resourceLoading,
			size: "large",
			allowClear: true,
			showSearch: true,
			open: selectOpen,
			onDropdownVisibleChange: setSelectOpen,
			filterOption: (str, option) => {
				return (option.labelText || "").toLowerCase().includes((str || "").toLowerCase());
			}
		}, renderOptions(state.service.resources || [], "form_record_id", "label", "resource")))))), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			hidden: true,
			name: "quantity"
		}, /* @__PURE__ */ react.default.createElement(antd.InputNumber, null)), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			hidden: true,
			name: "like_status"
		}, /* @__PURE__ */ react.default.createElement(antd.Input, null))), !isEventBookingMode && isDayBookingMode && !require_utils$2.isDayBookingProduct(state.service.cacheItem, state) ? /* @__PURE__ */ react.default.createElement(antd.Col, { span: 24 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			label: _pisell_utils.locales.getText("pisell2.text.quantity"),
			name: "quantity",
			rules: [{ required: true }]
		}, /* @__PURE__ */ react.default.createElement(antd.InputNumber, {
			size: "large",
			style: { width: "100%" },
			min: 1,
			max: 999999,
			formatter: (value) => {
				if (value !== void 0) return Math.floor(value);
				return value;
			}
		}))) : null))), showResource && errorList.map((d, i) => {
			return /* @__PURE__ */ react.default.createElement(antd.Alert, {
				key: d.type,
				message: d.label,
				type: "warning",
				showIcon: true,
				style: { marginBottom: 12 }
			});
		}))), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__booking-service-body-edit-footer" }, /* @__PURE__ */ react.default.createElement("div", {
			className: "pisell-lowcode__booking-service-delete-wrap",
			onClick: handleDeleteProduct
		}, /* @__PURE__ */ react.default.createElement(_pisell_icon_es_Delete_wght300_24px.default, { className: "pisell-lowcode__booking-service-delete-icon" })), /* @__PURE__ */ react.default.createElement(antd.Button, {
			type: "primary",
			className: "pisell-lowcode__booking-service-body-edit-footer-apple",
			disabled: resourceLoading,
			onClick: () => {
				form.submit();
			}
		}, _pisell_utils.locales.getText("pisell2.text.apply"))))));
	}, [
		state.service.changeService,
		state.service.editModal,
		(_state$service$cacheI13 = state.service.cacheItem) === null || _state$service$cacheI13 === void 0 ? void 0 : _state$service$cacheI13.autoClose,
		_pisell_utils.locales,
		(_state$service10 = state.service) === null || _state$service10 === void 0 || (_state$service10 = _state$service10.cacheItem) === null || _state$service10 === void 0 || (_state$service10 = _state$service10._extend) === null || _state$service10 === void 0 ? void 0 : _state$service10.product_name,
		bundles,
		state.amountSymbol,
		state.channelDisabledEdit,
		(_state$service$cacheI14 = state.service.cacheItem) === null || _state$service$cacheI14 === void 0 || (_state$service$cacheI14 = _state$service$cacheI14._extend) === null || _state$service$cacheI14 === void 0 ? void 0 : _state$service$cacheI14.origin_total,
		isDiscount,
		isReason,
		state.renderType,
		(_state$bookingConfig4 = state.bookingConfig) === null || _state$bookingConfig4 === void 0 || (_state$bookingConfig4 = _state$bookingConfig4.config) === null || _state$bookingConfig4 === void 0 || (_state$bookingConfig4 = _state$bookingConfig4.basic) === null || _state$bookingConfig4 === void 0 || (_state$bookingConfig4 = _state$bookingConfig4.service_time) === null || _state$bookingConfig4 === void 0 ? void 0 : _state$bookingConfig4.value,
		SelectTime,
		durationProps,
		timeObj,
		useResource,
		useLikeStatus,
		resourceLoading,
		selectOpen,
		state.service.resources,
		errorList,
		useTotal,
		useStartDate,
		useEndDate,
		showResource,
		holderLists,
		multiDayPrices,
		currentTab,
		items,
		isEventBookingMode
	]);
};
var editService_default = (0, react.forwardRef)(Info);
//#endregion
exports.default = editService_default;
