const require_runtime = require("../../../_virtual/_rolldown/runtime.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_utilsByBooking = require("../../../components/booking/info2/utilsByBooking.js");
const require_utils = require("../../../components/booking/info2/service/addService/utils.js");
const require_utils$1 = require("../../../components/booking/info/service2/Group/utils.js");
const require_utils$2 = require("../../../components/booking/info/service2/utils.js");
const require_utils$3 = require("../../../components/booking/utils.js");
const require_useEngineContext = require("../../../hooks/useEngineContext.js");
const require_index = require("../../../pro/compensatedPisellContainer/index.js");
const require_withResponsive = require("../../../responsive/withResponsive.js");
const require_index$1 = require("../../../components/booking/materiels/duration/index.js");
const require_index$2 = require("../../../components/booking/info2/service/editService/Capacity/index.js");
const require_index$3 = require("../../../components/booking/info2/service/editService/Resources/index.js");
const require_index$4 = require("../../../components/booking/info2/service/editService/Holder/index.js");
const require_index$5 = require("../../../components/booking/components/collapsibleList/index.js");
const require_utils$4 = require("../../../components/booking/components/collapsibleList/utils.js");
const require_index$6 = require("../../noteModal/index.js");
const require_index$7 = require("../../../pro/priceKeyboard/components/discountKeyboard/index.js");
const require_index$8 = require("../../../components/booking/info/service/editService/EditTabs/index.js");
const require_resolveCacheItemForResourceCheck = require("./resolveCacheItemForResourceCheck.js");
const require_SalesSdkBookingList = require("./SalesSdkBookingList.js");
const require_buildEditedCacheItem = require("./buildEditedCacheItem.js");
const require_normalizeResourceDisplay = require("./normalizeResourceDisplay.js");
const require_useBookingEditPetState = require("./useBookingEditPetState.js");
const require_useBookingEditProduct = require("./useBookingEditProduct.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 classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let _pisell_icon_es_ArrowLeft = require("@pisell/icon/es/ArrowLeft");
_pisell_icon_es_ArrowLeft = require_runtime.__toESM(_pisell_icon_es_ArrowLeft);
require("../../../components/booking/components/drawer/index.less");
let ahooks = require("ahooks");
require("../../../components/booking/info2/service/editService/index.less");
//#region src/plus/salesSdk/bookingEditService/BookingEditServiceDrawer.tsx
let submitLock = false;
const BookingEditServiceDrawerInner = (props) => {
	var _context$appHelper, _context$appHelper2, _context$appHelper3, _bookingState$booking2, _bookingState$booking3, _cacheItem$_extend2, _cacheItem$_extend4, _cacheItem$_extend6, _window$BaseMaterials, _cacheItem$_extend8, _cacheItem$_extend9, _cacheItem$_extend10, _cacheItem$_extend11, _cacheItem$_extend12, _bookingState$booking4, _bookingState$channel, _bookingState$booking5, _bookingState$service, _bookingState$client;
	const { open, cacheItem: cacheItemProp, onConfirm, onCancel, bookingState: baseBookingState, onCacheItemChange, showNoteButton = true, variant } = props;
	const [form] = antd.Form.useForm();
	const useTotal = antd.Form.useWatch("total", form);
	const useResource = antd.Form.useWatch("resource", form);
	const useStartTime = antd.Form.useWatch("start_time", form);
	const useDuration = antd.Form.useWatch("duration", form);
	antd.Form.useWatch("holder_id", form);
	const useNote = antd.Form.useWatch("note", form);
	const useStartDate = antd.Form.useWatch("start_date", form);
	const useEndDate = antd.Form.useWatch("end_date", form);
	const resourcesRef = (0, react.useRef)(null);
	const isChangeTotal = (0, react.useRef)(false);
	/** 防止 getResources → 更新 cacheItem → 再次灌表单的循环 */
	const isRefreshingResourcesRef = (0, react.useRef)(false);
	const prevDrawerOpenRef = (0, react.useRef)(false);
	const [noteModalOpen, setNoteModalOpen] = (0, react.useState)(false);
	const [currentTab, setCurrentTab] = (0, react.useState)("batch_edit");
	const [maskClosable, setMaskClosable] = (0, react.useState)(false);
	const [val, setVal] = (0, react.useState)(false);
	const context = require_useEngineContext.default();
	const getData = (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.getData;
	const action = context === null || context === void 0 || (_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 ? void 0 : _context$appHelper2.action;
	const engineRequest = context === null || context === void 0 || (_context$appHelper3 = context.appHelper) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.utils) === null || _context$appHelper3 === void 0 ? void 0 : _context$appHelper3.request;
	const isPhoneVariant = variant === "phone";
	const { pet, dispatch: petDispatch, apis } = require_useBookingEditPetState.useBookingEditPetState(open, baseBookingState, engineRequest);
	const bookingState = (0, react.useMemo)(() => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, baseBookingState), {}, {
		action,
		apis,
		pet,
		service: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, baseBookingState.service), {}, { cacheItem: cacheItemProp })
	}), [
		baseBookingState,
		cacheItemProp,
		action,
		apis,
		pet
	]);
	const cacheItem = cacheItemProp;
	const isNormalProduct = (0, react.useMemo)(() => {
		if (!cacheItem) return true;
		return require_utils$2.isNormalProductByDurationSchedule(cacheItem);
	}, [cacheItem]);
	const getCurrentCacheItem = (0, ahooks.useMemoizedFn)((_cacheItem) => {
		const values = form.getFieldsValue();
		return require_resolveCacheItemForResourceCheck.resolveCacheItemForResourceCheck(_cacheItem || cacheItem, values);
	});
	const durationProps = (0, react.useMemo)(() => {
		var _bookingState$booking;
		return require_utils.getDurationProps({
			cacheItem: getCurrentCacheItem(),
			useStartTime,
			slice: (_bookingState$booking = bookingState.bookingConfig) === null || _bookingState$booking === void 0 || (_bookingState$booking = _bookingState$booking.config) === null || _bookingState$booking === void 0 || (_bookingState$booking = _bookingState$booking.basic) === null || _bookingState$booking === void 0 ? void 0 : _bookingState$booking.service_time
		});
	}, [
		cacheItem,
		useStartTime,
		useResource,
		(_bookingState$booking2 = bookingState.bookingConfig) === null || _bookingState$booking2 === void 0 || (_bookingState$booking2 = _bookingState$booking2.config) === null || _bookingState$booking2 === void 0 || (_bookingState$booking2 = _bookingState$booking2.basic) === null || _bookingState$booking2 === void 0 ? void 0 : _bookingState$booking2.service_time
	]);
	const flexibleOption = (0, react.useMemo)(() => {
		return require_utils.getFlexibleOption({ durationProps });
	}, [durationProps, _pisell_utils.locales.locale]);
	const timeObj = (0, react.useMemo)(() => {
		return require_utils.getTimeObj({
			cacheItem: getCurrentCacheItem(),
			durationProps,
			useStartTime,
			currentResource: null,
			state: bookingState,
			useDuration
		});
	}, [
		durationProps,
		useStartTime,
		useDuration,
		(_bookingState$booking3 = bookingState.bookingConfig) === null || _bookingState$booking3 === void 0 || (_bookingState$booking3 = _bookingState$booking3.config) === null || _bookingState$booking3 === void 0 || (_bookingState$booking3 = _bookingState$booking3.basic) === null || _bookingState$booking3 === void 0 ? void 0 : _bookingState$booking3.service_time,
		cacheItem
	]);
	(0, react.useEffect)(() => {
		try {
			var _useDuration$indexOf;
			if ((useDuration === null || useDuration === void 0 || (_useDuration$indexOf = useDuration.indexOf) === null || _useDuration$indexOf === void 0 ? void 0 : _useDuration$indexOf.call(useDuration, "flexible_")) === 0 && flexibleOption) form.setFieldsValue({ duration: flexibleOption.value });
		} catch (_unused) {}
	}, [
		useDuration,
		flexibleOption,
		form
	]);
	const getDiscount = (0, ahooks.useMemoizedFn)(() => {
		var _cacheItem$_extend;
		const oPrice = Number((cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend = cacheItem._extend) === null || _cacheItem$_extend === void 0 ? void 0 : _cacheItem$_extend.origin_total) || 0);
		const 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, bookingState.amountSymbol) + "";
			else discount += "+" + (0, _pisell_utils.formatAmount)(cPrice - oPrice, 2, bookingState.amountSymbol);
		}
		form.setFieldsValue({ discount });
	});
	const updateCacheItem = (0, ahooks.useMemoizedFn)((next) => {
		onCacheItemChange(next);
	});
	/** 是否具备重算资源可用性所需的时间上下文（含 session 场次）。 */
	const hasBookingTimeForResources = (0, ahooks.useMemoizedFn)((item) => {
		var _ext$other;
		const current = item || getCurrentCacheItem();
		const ext = (current === null || current === void 0 ? void 0 : current._extend) || {};
		if (ext.start_time || ext.end_time) return true;
		if ((_ext$other = ext.other) === null || _ext$other === void 0 ? void 0 : _ext$other.session) return true;
		if (ext.duration != null && ext.duration !== "") return true;
		if (ext.endDate || ext.end_date) return true;
		return false;
	});
	const resolveResourceMapsForErrors = (0, ahooks.useMemoizedFn)(() => {
		var _current$_data$resour, _current$_data, _cacheItem$_data;
		const current = getCurrentCacheItem();
		const origin = (_current$_data$resour = current === null || current === void 0 || (_current$_data = current._data) === null || _current$_data === void 0 ? void 0 : _current$_data.resourcesOrigin) !== null && _current$_data$resour !== void 0 ? _current$_data$resour : cacheItem === null || cacheItem === void 0 || (_cacheItem$_data = cacheItem._data) === null || _cacheItem$_data === void 0 ? void 0 : _cacheItem$_data.resourcesOrigin;
		if (!Array.isArray(origin) || !origin.length) {
			var _current$_data2;
			return current === null || current === void 0 || (_current$_data2 = current._data) === null || _current$_data2 === void 0 ? void 0 : _current$_data2.resourceMaps;
		}
		try {
			var _res$maps, _current$_data3;
			const res = require_utils.formatResources({
				cacheItem: current,
				resourcesOrigin: origin
			});
			return (_res$maps = res === null || res === void 0 ? void 0 : res.maps) !== null && _res$maps !== void 0 ? _res$maps : current === null || current === void 0 || (_current$_data3 = current._data) === null || _current$_data3 === void 0 ? void 0 : _current$_data3.resourceMaps;
		} catch (err) {
			var _current$_data4;
			console.warn("[SalesSdk] resolveResourceMapsForErrors formatResources 失败", err);
			return current === null || current === void 0 || (_current$_data4 = current._data) === null || _current$_data4 === void 0 ? void 0 : _current$_data4.resourceMaps;
		}
	});
	const getResources = (0, ahooks.useMemoizedFn)((overrideItem) => {
		var _baseItem$_data;
		const baseItem = overrideItem || cacheItem;
		if (!(baseItem === null || baseItem === void 0 || (_baseItem$_data = baseItem._data) === null || _baseItem$_data === void 0 || (_baseItem$_data = _baseItem$_data.resourcesOrigin) === null || _baseItem$_data === void 0 ? void 0 : _baseItem$_data.length) || isRefreshingResourcesRef.current) return;
		isRefreshingResourcesRef.current = true;
		try {
			const res = require_utils.formatResources({
				cacheItem: overrideItem ? require_resolveCacheItemForResourceCheck.resolveCacheItemForResourceCheck(overrideItem, form.getFieldsValue()) : getCurrentCacheItem(),
				resourcesOrigin: baseItem._data.resourcesOrigin
			});
			updateCacheItem(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, baseItem), {}, { _data: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, baseItem._data), {}, {
				resources: require_normalizeResourceDisplay.normalizeResourceDisplayList(res === null || res === void 0 ? void 0 : res.list),
				resourceMaps: require_normalizeResourceDisplay.normalizeResourceDisplayMaps(res === null || res === void 0 ? void 0 : res.maps)
			}) }));
			updateResourceErrors();
		} finally {
			queueMicrotask(() => {
				isRefreshingResourcesRef.current = false;
			});
		}
	});
	const updateResourceErrors = (0, ahooks.useMemoizedFn)(() => {
		const { resource } = form.getFieldsValue();
		if (!resource) return;
		const maps = resolveResourceMapsForErrors();
		const cacheForErrors = getCurrentCacheItem();
		const nextResource = require_objectSpread2._objectSpread2({}, resource);
		let changed = false;
		for (const formId in nextResource) nextResource[formId] = nextResource[formId].map((d) => {
			var _maps$formId;
			const errors = require_utilsByBooking.getErrorList(maps === null || maps === void 0 || (_maps$formId = maps[formId]) === null || _maps$formId === void 0 || (_maps$formId = _maps$formId.renderListMaps) === null || _maps$formId === void 0 ? void 0 : _maps$formId[d === null || d === void 0 ? void 0 : d.relation_id], cacheForErrors);
			const prevErrors = d === null || d === void 0 ? void 0 : d.errors;
			if ((prevErrors === null || prevErrors === void 0 ? void 0 : prevErrors.length) !== (errors === null || errors === void 0 ? void 0 : errors.length) || (prevErrors === null || prevErrors === void 0 ? void 0 : prevErrors.some((item, index) => {
				var _errors$index;
				return (item === null || item === void 0 ? void 0 : item.type) !== (errors === null || errors === void 0 || (_errors$index = errors[index]) === null || _errors$index === void 0 ? void 0 : _errors$index.type);
			}))) changed = true;
			return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, d), {}, { errors });
		});
		if (changed) form.setFieldsValue({ resource: nextResource });
	});
	/** 仅跟踪选中的 relation_id，避免 updateResourceErrors 写回 form 时死循环 */
	const resourceSelectionKey = (0, react.useMemo)(() => {
		if (!useResource || typeof useResource !== "object") return "";
		return Object.keys(useResource).sort().map((formId) => {
			const rows = useResource[formId];
			if (!Array.isArray(rows)) return `${formId}:`;
			return `${formId}:${rows.map((r) => r === null || r === void 0 ? void 0 : r.relation_id).join(",")}`;
		}).join("|");
	}, [useResource]);
	(0, ahooks.useUpdateEffect)(() => {
		if (!open || !cacheItem || bookingState.renderType === "eventBooking") return;
		if (!hasBookingTimeForResources()) return;
		getResources();
	}, [
		useStartTime,
		useDuration,
		useEndDate,
		bookingState.renderType,
		bookingState.service.resourcesOrigin
	]);
	/** 手动切换资源后重算 errors（maps 已在 getResources / 打开抽屉时刷新） */
	(0, ahooks.useUpdateEffect)(() => {
		var _cacheItem$_data2;
		if (!open || !(cacheItem === null || cacheItem === void 0 || (_cacheItem$_data2 = cacheItem._data) === null || _cacheItem$_data2 === void 0 ? void 0 : _cacheItem$_data2.resourceMaps) || !resourceSelectionKey) return;
		updateResourceErrors();
	}, [resourceSelectionKey]);
	(0, react.useEffect)(() => {
		getDiscount();
	}, [
		useTotal,
		cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend2 = cacheItem._extend) === null || _cacheItem$_extend2 === void 0 ? void 0 : _cacheItem$_extend2.origin_total,
		getDiscount
	]);
	const bundles = (0, react.useMemo)(() => {
		var _cacheItem$_extend3;
		return (cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend3 = cacheItem._extend) === null || _cacheItem$_extend3 === void 0 || (_cacheItem$_extend3 = _cacheItem$_extend3.other) === null || _cacheItem$_extend3 === void 0 ? void 0 : _cacheItem$_extend3.bundle) || [];
	}, [cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend4 = cacheItem._extend) === null || _cacheItem$_extend4 === void 0 || (_cacheItem$_extend4 = _cacheItem$_extend4.other) === null || _cacheItem$_extend4 === void 0 ? void 0 : _cacheItem$_extend4.bundle]);
	const { run: setEditDataRun } = (0, ahooks.useDebounceFn)((item) => setEditData(item), {
		wait: 50,
		leading: true,
		trailing: false
	});
	const setEditData = (0, ahooks.useMemoizedFn)((item) => {
		var _target$_data, _target$_data2;
		setCurrentTab("batch_edit");
		isChangeTotal.current = false;
		const target = item || cacheItem;
		if (!(target === null || target === void 0 ? void 0 : target._extend)) return;
		const values = target._extend;
		form.resetFields();
		form.setFieldsValue({
			capacity: values.capacity,
			discount_reason: values.discount_reason,
			duration: values.duration,
			endDate: values.endDate,
			end_date: values.end_date,
			origin_total: values.origin_total,
			price: values.price,
			product_name: values.product_name,
			quantity: values.quantity,
			resource: values.resource,
			startDate: values.startDate,
			start_time: values.start_time,
			start_date: values.start_date,
			total: values.total,
			holder_id: values.holder_id,
			note: values.note
		});
		if (target === null || target === void 0 || (_target$_data = target._data) === null || _target$_data === void 0 || (_target$_data = _target$_data.resourcesOrigin) === null || _target$_data === void 0 ? void 0 : _target$_data.length) queueMicrotask(() => getResources());
		else if (target === null || target === void 0 || (_target$_data2 = target._data) === null || _target$_data2 === void 0 ? void 0 : _target$_data2.resourceMaps) updateResourceErrors();
	});
	/** 仅在抽屉从关→开时灌入表单；避免 getResources 更新 cacheItem 后反复 resetFields */
	(0, react.useEffect)(() => {
		const justOpened = open && !prevDrawerOpenRef.current;
		prevDrawerOpenRef.current = open;
		if (justOpened && cacheItem) setEditDataRun(cacheItem);
	}, [
		open,
		cacheItem,
		setEditDataRun
	]);
	const isReason = (0, react.useMemo)(() => {
		var _cacheItem$_extend5;
		const oPrice = Number((cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend5 = cacheItem._extend) === null || _cacheItem$_extend5 === void 0 ? void 0 : _cacheItem$_extend5.origin_total) || 0);
		return Number(useTotal || 0) !== oPrice;
	}, [useTotal, cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend6 = cacheItem._extend) === null || _cacheItem$_extend6 === void 0 ? void 0 : _cacheItem$_extend6.origin_total]);
	const onFinish = (0, ahooks.useMemoizedFn)((values) => {
		var _resourcesRef$current, _resourcesRef$current2;
		const isSuccess = (_resourcesRef$current = resourcesRef.current) === null || _resourcesRef$current === void 0 || (_resourcesRef$current2 = _resourcesRef$current.check) === null || _resourcesRef$current2 === void 0 ? void 0 : _resourcesRef$current2.call(_resourcesRef$current);
		if (isShowTimeAndResource && !isSuccess) return;
		if (submitLock) return;
		submitLock = true;
		setTimeout(() => {
			submitLock = false;
		}, 1500);
		const edited = require_buildEditedCacheItem.buildEditedCacheItem({
			values,
			cacheItem: getCurrentCacheItem(),
			isEditGroup: !!items.length,
			isChangeTotal: isChangeTotal.current,
			isPriceIncludeTax: getData === null || getData === void 0 ? void 0 : getData("is_price_include_tax")
		});
		form.resetFields();
		onConfirm(edited);
	});
	const isShowTimeAndResource = (0, react.useMemo)(() => {
		if (bookingState.renderType !== "eventBooking" && !isNormalProduct) return true;
		return false;
	}, [bookingState.renderType, isNormalProduct]);
	const SelectTime = (_window$BaseMaterials = window.BaseMaterials) === null || _window$BaseMaterials === void 0 ? void 0 : _window$BaseMaterials.SelectTime;
	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,
		cacheItem,
		useTotal
	]);
	const isEditGroup = (0, react.useMemo)(() => !!items.length, [items]);
	const updateMultiDay = (0, ahooks.useMemoizedFn)(function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* ({ start_date, end_date, duration }) {
			const nextItem = yield require_utils.getMultiDay({
				start_date,
				end_date,
				state: bookingState,
				cacheItem: getCurrentCacheItem()
			});
			if (duration !== void 0) nextItem._extend.duration = duration;
			nextItem._extend.items = require_utils$1.createBookingItemsByGroup(nextItem);
			nextItem._extend = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, nextItem._extend), require_utils$1.getGroupTotalPrice(nextItem._extend.items));
			updateCacheItem(nextItem);
			form.setFieldsValue({ total: nextItem._extend.total });
		});
		return function(_x) {
			return _ref.apply(this, arguments);
		};
	}());
	const onValuesChange = (0, ahooks.useMemoizedFn)((changedValues) => {
		if (!isEditGroup) return;
		if (changedValues === null || changedValues === void 0 ? void 0 : changedValues.duration) {
			const end_date = (0, dayjs.default)(useStartDate).add(changedValues.duration, "day");
			form.setFieldsValue({ end_date });
			return updateMultiDay({
				start_date: useStartDate,
				end_date,
				duration: changedValues.duration
			});
		}
		if (changedValues === null || changedValues === void 0 ? void 0 : changedValues.start_date) {
			const startDate = (0, dayjs.default)(changedValues.start_date);
			const endDate = (0, dayjs.default)(useEndDate);
			if (startDate.isAfter(endDate)) {
				form.setFieldsValue({
					duration: void 0,
					end_date: void 0
				});
				return;
			}
		}
		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
			});
			form.setFieldsValue({ duration });
		}
	});
	(0, react.useEffect)(() => {
		if (isShowTimeAndResource) {
			setVal(true);
			return;
		}
		setVal(false);
	}, [isShowTimeAndResource]);
	const handleTotalChange = () => {
		isChangeTotal.current = true;
	};
	const handleNoteConfirm = (noteValue) => {
		form.setFieldsValue({ note: noteValue });
		setNoteModalOpen(false);
	};
	const { canEditProduct, handleEditProduct, editingProduct } = require_useBookingEditProduct.useBookingEditProduct({
		cacheItem,
		bookingState,
		form,
		onCacheItemChange: updateCacheItem,
		onAfterProductEdit: getResources,
		resetManualPriceChange: () => {
			isChangeTotal.current = false;
		}
	});
	const drawerOpen = open && !(cacheItem === null || cacheItem === void 0 ? void 0 : cacheItem.autoClose);
	(0, react.useEffect)(() => {
		let timer = null;
		if (drawerOpen) timer = setTimeout(() => setMaskClosable(true), 200);
		else setMaskClosable(false);
		return () => {
			if (timer) clearTimeout(timer);
		};
	}, [drawerOpen]);
	const productName = (0, react.useMemo)(() => {
		var _cacheItem$_extend7;
		return /* @__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" }, (cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend7 = cacheItem._extend) === null || _cacheItem$_extend7 === void 0 ? void 0 : _cacheItem$_extend7.product_name) || "-"), canEditProduct && /* @__PURE__ */ react.default.createElement(antd.Button, {
			loading: editingProduct,
			disabled: bookingState.channelDisabledEdit,
			onClick: handleEditProduct
		}, _pisell_utils.locales.getText("pisell2.text.edit"))), /* @__PURE__ */ react.default.createElement(require_index$5.default, {
			style: { marginTop: bundles.length ? "8px" : 0 },
			list: bundles,
			renderItem: (item) => require_utils$4.renderBundles(item, bookingState.amountSymbol)
		}))));
	}, [
		bundles,
		bookingState.amountSymbol,
		bookingState.channelDisabledEdit,
		cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend8 = cacheItem._extend) === null || _cacheItem$_extend8 === void 0 ? void 0 : _cacheItem$_extend8.product_name,
		canEditProduct,
		editingProduct,
		handleEditProduct
	]);
	const price = /* @__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 !== (cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend9 = cacheItem._extend) === null || _cacheItem$_extend9 === void 0 ? void 0 : _cacheItem$_extend9.origin_total) && _pisell_utils.locales.getText("page.booking.text.price-extra")((0, _pisell_utils.formatAmount)(cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend10 = cacheItem._extend) === null || _cacheItem$_extend10 === void 0 ? void 0 : _cacheItem$_extend10.origin_total, 2, bookingState.amountSymbol), (0, _pisell_utils.formatAmount)(useTotal, 2, bookingState.amountSymbol))
	}, /* @__PURE__ */ react.default.createElement(require_index$7.default.InputNumber, {
		style: { width: "100%" },
		min: 0,
		precision: 2,
		prefix: bookingState.amountSymbol,
		onChange: handleTotalChange,
		disabled: bookingState.channelDisabledEdit,
		originalValue: (cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend11 = cacheItem._extend) === null || _cacheItem$_extend11 === void 0 ? void 0 : _cacheItem$_extend11.origin_total) || 0,
		placeholder: (cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend12 = cacheItem._extend) === null || _cacheItem$_extend12 === void 0 ? void 0 : _cacheItem$_extend12.origin_total) || "0",
		size: "large",
		keyboardProps: {
			containerProps: { renderType: "modal" },
			selectType: "dark"
		}
	})));
	const reason = 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;
	const DateCom = (position) => /* @__PURE__ */ react.default.createElement(antd.DatePicker, {
		className: "pisell-lowcode__booking-service-select-date",
		disabledDate: (current) => require_utils$2.disabledDate(current, position, bookingState.date.value),
		size: "large",
		style: { width: "100%" },
		format: bookingState.locale === "en" ? "DD/MM/YYYY" : "YYYY-MM-DD"
	});
	const startTime = /* @__PURE__ */ react.default.createElement(antd.Col, { span: 12 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: _pisell_utils.locales.getText(isEditGroup ? "pisell2.text.start_date" : "pisell2.text.start_time"),
		name: isEditGroup ? "start_date" : "start_time",
		rules: [{ required: true }]
	}, isEditGroup ? DateCom("start") : SelectTime ? /* @__PURE__ */ react.default.createElement(SelectTime, {
		slice: (_bookingState$booking4 = bookingState.bookingConfig) === null || _bookingState$booking4 === void 0 || (_bookingState$booking4 = _bookingState$booking4.config) === null || _bookingState$booking4 === void 0 || (_bookingState$booking4 = _bookingState$booking4.basic) === null || _bookingState$booking4 === void 0 || (_bookingState$booking4 = _bookingState$booking4.service_time) === null || _bookingState$booking4 === void 0 ? void 0 : _bookingState$booking4.value,
		timePickerProps: { style: { width: "100%" } },
		timeProps: { style: { zoom: .8 } }
	}) : null));
	const endTime = isEditGroup ? /* @__PURE__ */ react.default.createElement(antd.Col, { span: 12 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: _pisell_utils.locales.getText("pisell2.text.end_date"),
		name: "end_date"
	}, DateCom("end"))) : null;
	const durationField = /* @__PURE__ */ react.default.createElement(antd.Col, { span: isEditGroup ? 24 : 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 }))));
	const resource = /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		noStyle: true,
		name: "resource"
	}, /* @__PURE__ */ react.default.createElement(require_index$3.default, {
		ref: resourcesRef,
		state: bookingState,
		cacheItem,
		getCurrentCacheItem,
		config: {
			autoAllocation: true,
			resourceErrorIcon: true,
			disabled: (_bookingState$channel = bookingState.channelDisabledEdit) !== null && _bookingState$channel !== void 0 ? _bookingState$channel : false
		}
	}));
	const holder = /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		name: "holder_id",
		style: { width: "100%" },
		rules: [{
			required: (bookingState === null || bookingState === void 0 || (_bookingState$booking5 = bookingState.bookingConfig) === null || _bookingState$booking5 === void 0 || (_bookingState$booking5 = _bookingState$booking5.config) === null || _bookingState$booking5 === void 0 || (_bookingState$booking5 = _bookingState$booking5.basic) === null || _bookingState$booking5 === void 0 ? void 0 : _bookingState$booking5.subject_require) === "require",
			validator: (_rule, value, callback) => {
				var _bookingState$booking6, _cacheItem$_extend13;
				if ((bookingState === null || bookingState === void 0 || (_bookingState$booking6 = bookingState.bookingConfig) === null || _bookingState$booking6 === void 0 || (_bookingState$booking6 = _bookingState$booking6.config) === null || _bookingState$booking6 === void 0 || (_bookingState$booking6 = _bookingState$booking6.basic) === null || _bookingState$booking6 === void 0 ? void 0 : _bookingState$booking6.subject_require) === "require" && (!value || (value === null || value === void 0 ? void 0 : value.length) < ((cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend13 = cacheItem._extend) === null || _cacheItem$_extend13 === void 0 ? void 0 : _cacheItem$_extend13.quantity) || 1))) callback(_pisell_utils.locales.getText("page.booking.text.holder.length-error"));
				else callback();
			}
		}]
	}, /* @__PURE__ */ react.default.createElement(require_index$4.default, {
		state: bookingState,
		cacheItem,
		dispatch: petDispatch
	}));
	const capacity = /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		noStyle: true,
		name: "capacity"
	}, /* @__PURE__ */ react.default.createElement(require_index$2.default, {
		state: bookingState,
		cacheItem
	}));
	const quantity = /* @__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) => value !== void 0 ? Math.floor(value) : value
	})));
	const groupDom = /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, !!isEditGroup && /* @__PURE__ */ react.default.createElement(require_index$8.default, {
		value: currentTab,
		onChange: setCurrentTab
	}), /* @__PURE__ */ react.default.createElement("div", { style: { display: currentTab === "booking_list" ? "block" : "none" } }, /* @__PURE__ */ react.default.createElement(require_SalesSdkBookingList.SalesSdkBookingList, {
		items,
		bookingState
	})));
	const footer = /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-lowcode__booking-service-body-edit-footer",
		style: (bookingState === null || bookingState === void 0 ? void 0 : bookingState.isBookingTicket2) ? { justifyContent: "space-between" } : void 0
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__booking-service-body-edit-footer-left" }, showNoteButton && (bookingState === null || bookingState === void 0 ? void 0 : bookingState.isBookingTicket2) && /* @__PURE__ */ react.default.createElement(_pisell_materials.ConfigProvider, { theme: { token: { colorPrimary: "#0d7fa9" } } }, /* @__PURE__ */ react.default.createElement(antd.Button, {
		className: "pisell-lowcode__booking-service-buttons-item note-button",
		type: "primary",
		size: "large",
		onClick: () => setNoteModalOpen(true),
		style: {
			height: "48px",
			width: "140px"
		}
	}, _pisell_utils.locales.getText("pisell2.ticket-booking.note"), useNote && /* @__PURE__ */ react.default.createElement("span", { className: "note-indicator" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-info-circle2" }))))), /* @__PURE__ */ react.default.createElement(antd.Button, {
		type: "primary",
		className: "pisell-lowcode__booking-service-body-edit-footer-apple",
		disabled: !isNormalProduct && !((_bookingState$service = bookingState.service.resourcesOrigin) === null || _bookingState$service === void 0 ? void 0 : _bookingState$service.length),
		onClick: () => form.submit()
	}, _pisell_utils.locales.getText("pisell2.text.apply")));
	return /* @__PURE__ */ react.default.createElement(require_index.default, {
		renderType: "drawer",
		props: {
			maskClosable,
			title: false,
			closable: false,
			zIndex: editingProduct ? 900 : 1e3,
			forceRender: true,
			mask: bookingState.drawerMask,
			open: drawerOpen,
			placement: isPhoneVariant ? "bottom" : "right",
			width: isPhoneVariant ? "100%" : "600px",
			height: isPhoneVariant ? "95vh" : void 0,
			rootClassName: "booking-server-wrap",
			className: (0, classnames.default)("pisell-lowcode__booking-drawer", "pisell-lowcode__booking-drawer-hide-scrollbar"),
			push: false,
			bodyStyle: { padding: 0 },
			onClose: onCancel
		}
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__booking-drawer-title-wrap" }, /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-lowcode__booking-drawer-title-line",
		onClick: onCancel
	}, /* @__PURE__ */ react.default.createElement("span", { className: "pisell-lowcode__booking-drawer-back" }, /* @__PURE__ */ react.default.createElement(_pisell_icon_es_ArrowLeft.default, null)), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__booking-drawer-title pisell-lowcode__booking-drawer-title-no-wrap" }, _pisell_utils.locales.getText("pisell2.text.edit-service")))), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__booking-service-body-edit" }, groupDom, /* @__PURE__ */ react.default.createElement(antd.Form, {
		layout: "vertical",
		form,
		onFinish,
		onValuesChange,
		style: { display: currentTab === "batch_edit" ? "block" : "none" }
	}, /* @__PURE__ */ react.default.createElement(antd.Row, {
		style: { width: "100%" },
		gutter: [16, 0]
	}, productName, price, reason, val && isShowTimeAndResource && /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, startTime, endTime, durationField, resource, capacity, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		hidden: true,
		name: "quantity"
	}, /* @__PURE__ */ react.default.createElement(antd.InputNumber, null))), isNormalProduct && quantity, !require_utils$2.isNormalProductByDurationSchedule(cacheItem) && !require_utils$3.isWalkIn((_bookingState$client = bookingState.client) === null || _bookingState$client === void 0 || (_bookingState$client = _bookingState$client.value) === null || _bookingState$client === void 0 ? void 0 : _bookingState$client.id) && holder), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		noStyle: true,
		name: "note"
	}, noteModalOpen && /* @__PURE__ */ react.default.createElement(require_index$6.default, {
		open: noteModalOpen,
		value: form.getFieldValue("note"),
		onConfirm: handleNoteConfirm,
		onDelete: () => {
			form.setFieldsValue({ note: "" });
			setNoteModalOpen(false);
		},
		onCancel: () => setNoteModalOpen(false)
	}))), footer));
};
BookingEditServiceDrawerInner.displayName = "BookingEditServiceDrawer";
const BookingEditServiceDrawer = require_withResponsive.default(BookingEditServiceDrawerInner);
//#endregion
exports.BookingEditServiceDrawer = BookingEditServiceDrawer;
