import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _asyncToGenerator } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import { getErrorList } from "../../../components/booking/info2/utilsByBooking.js";
import { formatResources, getDurationProps, getFlexibleOption, getMultiDay, getTimeObj } from "../../../components/booking/info2/service/addService/utils.js";
import { createBookingItemsByGroup, getGroupTotalPrice } from "../../../components/booking/info/service2/Group/utils.js";
import { disabledDate, isNormalProductByDurationSchedule } from "../../../components/booking/info/service2/utils.js";
import { getDays, isWalkIn } from "../../../components/booking/utils.js";
import useEngineContext from "../../../hooks/useEngineContext.js";
import CompensatedPisellContainer from "../../../pro/compensatedPisellContainer/index.js";
import withResponsive from "../../../responsive/withResponsive.js";
import Duration from "../../../components/booking/materiels/duration/index.js";
import Capacity_default from "../../../components/booking/info2/service/editService/Capacity/index.js";
import Resources_default from "../../../components/booking/info2/service/editService/Resources/index.js";
import Holder from "../../../components/booking/info2/service/editService/Holder/index.js";
import CollapsibleList from "../../../components/booking/components/collapsibleList/index.js";
import { renderBundles } from "../../../components/booking/components/collapsibleList/utils.js";
import noteModal_default from "../../noteModal/index.js";
import DiscountKeyboard from "../../../pro/priceKeyboard/components/discountKeyboard/index.js";
import Demo from "../../../components/booking/info/service/editService/EditTabs/index.js";
import { resolveCacheItemForResourceCheck } from "./resolveCacheItemForResourceCheck.js";
import { SalesSdkBookingList } from "./SalesSdkBookingList.js";
import { buildEditedCacheItem } from "./buildEditedCacheItem.js";
import { normalizeResourceDisplayList, normalizeResourceDisplayMaps } from "./normalizeResourceDisplay.js";
import { useBookingEditPetState } from "./useBookingEditPetState.js";
import { useBookingEditProduct } from "./useBookingEditProduct.js";
import dayjs from "dayjs";
import React, { useEffect, useMemo, useRef, useState } from "react";
import { Button, Col, DatePicker, Form, Input, InputNumber, Row } from "antd";
import { formatAmount, locales } from "@pisell/utils";
import { ConfigProvider as ConfigProvider$1, Iconfont } from "@pisell/materials";
import classNames from "classnames";
import ArrowLeft from "@pisell/icon/es/ArrowLeft";
import "../../../components/booking/components/drawer/index.less";
import { useDebounceFn, useMemoizedFn, useUpdateEffect } from "ahooks";
import "../../../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] = Form.useForm();
	const useTotal = Form.useWatch("total", form);
	const useResource = Form.useWatch("resource", form);
	const useStartTime = Form.useWatch("start_time", form);
	const useDuration = Form.useWatch("duration", form);
	Form.useWatch("holder_id", form);
	const useNote = Form.useWatch("note", form);
	const useStartDate = Form.useWatch("start_date", form);
	const useEndDate = Form.useWatch("end_date", form);
	const resourcesRef = useRef(null);
	const isChangeTotal = useRef(false);
	/** 防止 getResources → 更新 cacheItem → 再次灌表单的循环 */
	const isRefreshingResourcesRef = useRef(false);
	const prevDrawerOpenRef = useRef(false);
	const [noteModalOpen, setNoteModalOpen] = useState(false);
	const [currentTab, setCurrentTab] = useState("batch_edit");
	const [maskClosable, setMaskClosable] = useState(false);
	const [val, setVal] = useState(false);
	const context = useEngineContext();
	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 } = useBookingEditPetState(open, baseBookingState, engineRequest);
	const bookingState = useMemo(() => _objectSpread2(_objectSpread2({}, baseBookingState), {}, {
		action,
		apis,
		pet,
		service: _objectSpread2(_objectSpread2({}, baseBookingState.service), {}, { cacheItem: cacheItemProp })
	}), [
		baseBookingState,
		cacheItemProp,
		action,
		apis,
		pet
	]);
	const cacheItem = cacheItemProp;
	const isNormalProduct = useMemo(() => {
		if (!cacheItem) return true;
		return isNormalProductByDurationSchedule(cacheItem);
	}, [cacheItem]);
	const getCurrentCacheItem = useMemoizedFn((_cacheItem) => {
		const values = form.getFieldsValue();
		return resolveCacheItemForResourceCheck(_cacheItem || cacheItem, values);
	});
	const durationProps = useMemo(() => {
		var _bookingState$booking;
		return 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 = useMemo(() => {
		return getFlexibleOption({ durationProps });
	}, [durationProps, locales.locale]);
	const timeObj = useMemo(() => {
		return 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
	]);
	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 = 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 = locales.getText("pisell2.text.status.no-discount");
		else {
			discount = `${locales.getText("pisell2.text.status.manual")} `;
			if (cPrice < oPrice) discount += formatAmount(cPrice - oPrice, 2, bookingState.amountSymbol) + "";
			else discount += "+" + formatAmount(cPrice - oPrice, 2, bookingState.amountSymbol);
		}
		form.setFieldsValue({ discount });
	});
	const updateCacheItem = useMemoizedFn((next) => {
		onCacheItemChange(next);
	});
	/** 是否具备重算资源可用性所需的时间上下文（含 session 场次）。 */
	const hasBookingTimeForResources = 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 = 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 = 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 = 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 = formatResources({
				cacheItem: overrideItem ? resolveCacheItemForResourceCheck(overrideItem, form.getFieldsValue()) : getCurrentCacheItem(),
				resourcesOrigin: baseItem._data.resourcesOrigin
			});
			updateCacheItem(_objectSpread2(_objectSpread2({}, baseItem), {}, { _data: _objectSpread2(_objectSpread2({}, baseItem._data), {}, {
				resources: normalizeResourceDisplayList(res === null || res === void 0 ? void 0 : res.list),
				resourceMaps: normalizeResourceDisplayMaps(res === null || res === void 0 ? void 0 : res.maps)
			}) }));
			updateResourceErrors();
		} finally {
			queueMicrotask(() => {
				isRefreshingResourcesRef.current = false;
			});
		}
	});
	const updateResourceErrors = useMemoizedFn(() => {
		const { resource } = form.getFieldsValue();
		if (!resource) return;
		const maps = resolveResourceMapsForErrors();
		const cacheForErrors = getCurrentCacheItem();
		const nextResource = _objectSpread2({}, resource);
		let changed = false;
		for (const formId in nextResource) nextResource[formId] = nextResource[formId].map((d) => {
			var _maps$formId;
			const errors = 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 _objectSpread2(_objectSpread2({}, d), {}, { errors });
		});
		if (changed) form.setFieldsValue({ resource: nextResource });
	});
	/** 仅跟踪选中的 relation_id，避免 updateResourceErrors 写回 form 时死循环 */
	const resourceSelectionKey = 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]);
	useUpdateEffect(() => {
		if (!open || !cacheItem || bookingState.renderType === "eventBooking") return;
		if (!hasBookingTimeForResources()) return;
		getResources();
	}, [
		useStartTime,
		useDuration,
		useEndDate,
		bookingState.renderType,
		bookingState.service.resourcesOrigin
	]);
	/** 手动切换资源后重算 errors（maps 已在 getResources / 打开抽屉时刷新） */
	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]);
	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 = 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 } = useDebounceFn((item) => setEditData(item), {
		wait: 50,
		leading: true,
		trailing: false
	});
	const setEditData = 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 */
	useEffect(() => {
		const justOpened = open && !prevDrawerOpenRef.current;
		prevDrawerOpenRef.current = open;
		if (justOpened && cacheItem) setEditDataRun(cacheItem);
	}, [
		open,
		cacheItem,
		setEditDataRun
	]);
	const isReason = 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 = 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 = 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 = 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 = 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 = useMemo(() => !!items.length, [items]);
	const updateMultiDay = useMemoizedFn(function() {
		var _ref = _asyncToGenerator(function* ({ start_date, end_date, duration }) {
			const nextItem = yield getMultiDay({
				start_date,
				end_date,
				state: bookingState,
				cacheItem: getCurrentCacheItem()
			});
			if (duration !== void 0) nextItem._extend.duration = duration;
			nextItem._extend.items = createBookingItemsByGroup(nextItem);
			nextItem._extend = _objectSpread2(_objectSpread2({}, nextItem._extend), getGroupTotalPrice(nextItem._extend.items));
			updateCacheItem(nextItem);
			form.setFieldsValue({ total: nextItem._extend.total });
		});
		return function(_x) {
			return _ref.apply(this, arguments);
		};
	}());
	const onValuesChange = useMemoizedFn((changedValues) => {
		if (!isEditGroup) return;
		if (changedValues === null || changedValues === void 0 ? void 0 : changedValues.duration) {
			const end_date = dayjs(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 = dayjs(changedValues.start_date);
			const endDate = dayjs(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 = 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 });
		}
	});
	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 } = useBookingEditProduct({
		cacheItem,
		bookingState,
		form,
		onCacheItemChange: updateCacheItem,
		onAfterProductEdit: getResources,
		resetManualPriceChange: () => {
			isChangeTotal.current = false;
		}
	});
	const drawerOpen = open && !(cacheItem === null || cacheItem === void 0 ? void 0 : cacheItem.autoClose);
	useEffect(() => {
		let timer = null;
		if (drawerOpen) timer = setTimeout(() => setMaskClosable(true), 200);
		else setMaskClosable(false);
		return () => {
			if (timer) clearTimeout(timer);
		};
	}, [drawerOpen]);
	const productName = useMemo(() => {
		var _cacheItem$_extend7;
		return /* @__PURE__ */ React.createElement(Col, { span: 24 }, /* @__PURE__ */ React.createElement(Form.Item, { name: "product_name" }, /* @__PURE__ */ React.createElement("div", { className: "current-service-info" }, /* @__PURE__ */ React.createElement("div", { className: "current-service-info-name-wrap" }, /* @__PURE__ */ React.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.createElement(Button, {
			loading: editingProduct,
			disabled: bookingState.channelDisabledEdit,
			onClick: handleEditProduct
		}, locales.getText("pisell2.text.edit"))), /* @__PURE__ */ React.createElement(CollapsibleList, {
			style: { marginTop: bundles.length ? "8px" : 0 },
			list: bundles,
			renderItem: (item) => 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.createElement(Col, { span: 24 }, /* @__PURE__ */ React.createElement(Form.Item, {
		label: 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) && locales.getText("page.booking.text.price-extra")(formatAmount(cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend10 = cacheItem._extend) === null || _cacheItem$_extend10 === void 0 ? void 0 : _cacheItem$_extend10.origin_total, 2, bookingState.amountSymbol), formatAmount(useTotal, 2, bookingState.amountSymbol))
	}, /* @__PURE__ */ React.createElement(DiscountKeyboard.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.createElement(Col, { span: 24 }, /* @__PURE__ */ React.createElement(Form.Item, {
		label: locales.getText("pisell2.text.discount-reason"),
		name: "discount_reason"
	}, /* @__PURE__ */ React.createElement(Input.TextArea, { size: "large" }))) : null;
	const DateCom = (position) => /* @__PURE__ */ React.createElement(DatePicker, {
		className: "pisell-lowcode__booking-service-select-date",
		disabledDate: (current) => 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.createElement(Col, { span: 12 }, /* @__PURE__ */ React.createElement(Form.Item, {
		label: 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.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.createElement(Col, { span: 12 }, /* @__PURE__ */ React.createElement(Form.Item, {
		label: locales.getText("pisell2.text.end_date"),
		name: "end_date"
	}, DateCom("end"))) : null;
	const durationField = /* @__PURE__ */ React.createElement(Col, { span: isEditGroup ? 24 : 12 }, /* @__PURE__ */ React.createElement(Form.Item, {
		label: locales.getText("pisell2.text.duration"),
		name: "duration",
		rules: [{ required: true }]
	}, /* @__PURE__ */ React.createElement(Duration, _objectSpread2(_objectSpread2({}, durationProps), {}, { timeObj }))));
	const resource = /* @__PURE__ */ React.createElement(Form.Item, {
		noStyle: true,
		name: "resource"
	}, /* @__PURE__ */ React.createElement(Resources_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.createElement(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(locales.getText("page.booking.text.holder.length-error"));
				else callback();
			}
		}]
	}, /* @__PURE__ */ React.createElement(Holder, {
		state: bookingState,
		cacheItem,
		dispatch: petDispatch
	}));
	const capacity = /* @__PURE__ */ React.createElement(Form.Item, {
		noStyle: true,
		name: "capacity"
	}, /* @__PURE__ */ React.createElement(Capacity_default, {
		state: bookingState,
		cacheItem
	}));
	const quantity = /* @__PURE__ */ React.createElement(Col, { span: 24 }, /* @__PURE__ */ React.createElement(Form.Item, {
		label: locales.getText("pisell2.text.quantity"),
		name: "quantity",
		rules: [{ required: true }]
	}, /* @__PURE__ */ React.createElement(InputNumber, {
		size: "large",
		style: { width: "100%" },
		min: 1,
		max: 999999,
		formatter: (value) => value !== void 0 ? Math.floor(value) : value
	})));
	const groupDom = /* @__PURE__ */ React.createElement(React.Fragment, null, !!isEditGroup && /* @__PURE__ */ React.createElement(Demo, {
		value: currentTab,
		onChange: setCurrentTab
	}), /* @__PURE__ */ React.createElement("div", { style: { display: currentTab === "booking_list" ? "block" : "none" } }, /* @__PURE__ */ React.createElement(SalesSdkBookingList, {
		items,
		bookingState
	})));
	const footer = /* @__PURE__ */ React.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.createElement("div", { className: "pisell-lowcode__booking-service-body-edit-footer-left" }, showNoteButton && (bookingState === null || bookingState === void 0 ? void 0 : bookingState.isBookingTicket2) && /* @__PURE__ */ React.createElement(ConfigProvider$1, { theme: { token: { colorPrimary: "#0d7fa9" } } }, /* @__PURE__ */ React.createElement(Button, {
		className: "pisell-lowcode__booking-service-buttons-item note-button",
		type: "primary",
		size: "large",
		onClick: () => setNoteModalOpen(true),
		style: {
			height: "48px",
			width: "140px"
		}
	}, locales.getText("pisell2.ticket-booking.note"), useNote && /* @__PURE__ */ React.createElement("span", { className: "note-indicator" }, /* @__PURE__ */ React.createElement(Iconfont, { type: "pisell2-info-circle2" }))))), /* @__PURE__ */ React.createElement(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()
	}, locales.getText("pisell2.text.apply")));
	return /* @__PURE__ */ React.createElement(CompensatedPisellContainer, {
		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: classNames("pisell-lowcode__booking-drawer", "pisell-lowcode__booking-drawer-hide-scrollbar"),
			push: false,
			bodyStyle: { padding: 0 },
			onClose: onCancel
		}
	}, /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-drawer-title-wrap" }, /* @__PURE__ */ React.createElement("div", {
		className: "pisell-lowcode__booking-drawer-title-line",
		onClick: onCancel
	}, /* @__PURE__ */ React.createElement("span", { className: "pisell-lowcode__booking-drawer-back" }, /* @__PURE__ */ React.createElement(ArrowLeft, null)), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-drawer-title pisell-lowcode__booking-drawer-title-no-wrap" }, locales.getText("pisell2.text.edit-service")))), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-service-body-edit" }, groupDom, /* @__PURE__ */ React.createElement(Form, {
		layout: "vertical",
		form,
		onFinish,
		onValuesChange,
		style: { display: currentTab === "batch_edit" ? "block" : "none" }
	}, /* @__PURE__ */ React.createElement(Row, {
		style: { width: "100%" },
		gutter: [16, 0]
	}, productName, price, reason, val && isShowTimeAndResource && /* @__PURE__ */ React.createElement(React.Fragment, null, startTime, endTime, durationField, resource, capacity, /* @__PURE__ */ React.createElement(Form.Item, {
		hidden: true,
		name: "quantity"
	}, /* @__PURE__ */ React.createElement(InputNumber, null))), isNormalProduct && quantity, !isNormalProductByDurationSchedule(cacheItem) && !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.createElement(Form.Item, {
		noStyle: true,
		name: "note"
	}, noteModalOpen && /* @__PURE__ */ React.createElement(noteModal_default, {
		open: noteModalOpen,
		value: form.getFieldValue("note"),
		onConfirm: handleNoteConfirm,
		onDelete: () => {
			form.setFieldsValue({ note: "" });
			setNoteModalOpen(false);
		},
		onCancel: () => setNoteModalOpen(false)
	}))), footer));
};
BookingEditServiceDrawerInner.displayName = "BookingEditServiceDrawer";
const BookingEditServiceDrawer = withResponsive(BookingEditServiceDrawerInner);
//#endregion
export { BookingEditServiceDrawer };
