import { _objectSpread2 } from "../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { getNoResource } from "../../../mock.js";
import { _asyncToGenerator } from "../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import { createBookingItemsByGroup, filterItemByGroupId, getGroupTotalPrice, isGroupBooking } from "../../service2/Group/utils.js";
import { formatResources, getDurationProps, getFlexibleOption, getMultiDay, getTimeObj } from "../addService/utils.js";
import { disabledDate, formatDayTime, isDayBooking, isDayBookingProduct, isDaysBooking, isEventBooking } from "../../service2/utils.js";
import { getDays, getErrorList, getProductTotalPrice, isSessionProduct } from "../../../utils.js";
import { editSessionProduct, getMultiDayPrices } from "../../utils.js";
import { Context } from "../../model.js";
import Drawer$2 from "../../../components/drawer/index.js";
import useEngineContext from "../../../../../hooks/useEngineContext.js";
import Duration from "../../../materiels/duration/index.js";
import Like from "../like/index.js";
import CollapsibleList from "../../../components/collapsibleList/index.js";
import { renderBundles } from "../../../components/collapsibleList/utils.js";
import Demo from "./EditTabs/index.js";
import useSelectPet from "../../service2/hooks/useSelectPet.js";
import BookingList from "./BookingList/index.js";
import { useService } from "../serviceManager/index.js";
import Holder from "../../../materiels/holder/index.js";
import { getIsPartyRoomResourceShop } from "./constants.js";
import dayjs from "dayjs";
import React, { forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
import { Alert, Button, Col, DatePicker, Form, Input, InputNumber, Row, Select } from "antd";
import { formatAmount, locales } from "@pisell/utils";
import { Page, PisellAdjustPriceInputNumber } from "@pisell/materials";
import { useMemoizedFn, useUpdateEffect } from "ahooks";
import Delete_wght300_24px from "@pisell/icon/es/Delete_wght300_24px";
import "./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] = Form.useForm();
	const context = useEngineContext();
	const useTotal = Form.useWatch("total", form);
	const useLikeStatus = Form.useWatch("like_status", form);
	const useResource = Form.useWatch("resource", form);
	const useStartTime = Form.useWatch("start_time", form);
	const useDuration = Form.useWatch("duration", form);
	const useStartDate = Form.useWatch("start_date", form);
	const useEndDate = Form.useWatch("end_date", form);
	const [resourceLoading, setResourceLoading] = useState(false);
	const { state, dispatch } = useContext(Context);
	const [selectOpen, setSelectOpen] = useState();
	const { holderLists } = useSelectPet(state);
	const isChangeTotal = useRef(false);
	const { editBookingData, editBooking } = useService({
		state,
		dispatch
	});
	const [currentTab, setCurrentTab] = useState("batch_edit");
	const isDayBookingMode = useMemo(() => {
		return isDayBooking(state);
	}, [state === null || state === void 0 ? void 0 : state.renderType]);
	const isDaysBookingMode = useMemo(() => {
		return isDaysBooking(state);
	}, [state === null || state === void 0 ? void 0 : state.renderType]);
	const isEventBookingMode = useMemo(() => {
		return 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 _objectSpread2(_objectSpread2({}, _item), {}, { _extend: _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 = 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 = useMemo(() => {
		var _state$bookingConfig;
		return 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 = useMemo(() => {
		return getFlexibleOption({ durationProps });
	}, [durationProps, locales.locale]);
	/**
	* @title: 时间切片
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 13:37
	*/
	const timeObj = useMemo(() => {
		return getTimeObj({
			durationProps,
			useStartTime,
			currentResource,
			state,
			useDuration
		});
	}, [
		state,
		locales.locale,
		useDuration,
		useStartTime,
		flexibleOption
	]);
	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 = _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: 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 = 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 (isGroupBooking(_id)) _list = 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 = useCallback((array, value = "value", label = "label", type) => {
		return array.map((d) => {
			let props = {};
			if (type === "resource") props.labelText = d.labelText;
			return /* @__PURE__ */ React.createElement(Select.Option, _objectSpread2({
				value: d[value],
				key: d[value]
			}, props), d[label]);
		});
	}, []);
	/**
	* @title: 点赞资源
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:02
	*/
	const handleLikeResource = 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 = locales.getText("pisell2.text.status.no-discount");
		else {
			discount = `${locales.getText("pisell2.text.status.manual")} `;
			if (cPrice < oPrice) discount += formatAmount(cPrice - oPrice, 2, state.amountSymbol) + "";
			else discount += "+" + 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 = useMemoizedFn(function() {
		var _ref2 = _asyncToGenerator(function* (values) {
			if (submitLock) return;
			submitLock = true;
			setTimeout(() => {
				submitLock = false;
			}, 1500);
			const data = yield editBookingData({ changeValues: _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 = useMemoizedFn((_cacheItem, open, openProductDetail) => {
		setCurrentTab("batch_edit");
		isChangeTotal.current = false;
		let cacheItem = _cacheItem || state.service.cacheItem;
		let values = cacheItem._extend;
		values = _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 = 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 = useMemo(() => {
		return getErrorList(currentResource, getCurrentCacheItem(), isDayBookingMode);
	}, [
		currentResource,
		useDuration,
		useStartTime
	]);
	/**
	* @title: 开始时间 和 服务时间 发生变化时,重新计算资源
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:07
	*/
	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 = useMemo(() => {
		return state.isBookingCreatePage || state.isTerminalDayBookingPage;
	}, [state.isBookingCreatePage, state.isTerminalDayBookingPage]);
	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
	*/
	useEffect(() => {
		getErrorMsg();
	}, [
		useResource,
		useStartTime,
		useDuration,
		useStartDate,
		useEndDate
	]);
	/**
	* @title: 价格发生变化,重新计算折扣
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 14:08
	*/
	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 = 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]);
	useEffect(() => {
		if (useResource === 0) handleLikeResource("common");
	}, [useResource]);
	const bundles = 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 = useMemo(() => {
		var _state$service7;
		return Object.entries(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 = _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 } = formatDayTime({
						startDate: useStartDate || state.date.value,
						endDate: useEndDate || state.date.end_date
					});
					if (dayjs(startDateTime).isAfter(dayjs(endDateTime))) return;
					params.check_time = {
						start_time: dayjs(startDateTime).format(format),
						end_time: dayjs(endDateTime).format(format)
					};
				} else params.with_date_times = state.date.value.format("YYYY-MM-DD");
				const codes = 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(_objectSpread2({
					skip: 1,
					num: 1e3,
					codes,
					_config: { abort: true }
				}, params));
				dispatch({
					type: "setService",
					payload: { resourcesOrigin: [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);
		};
	}();
	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 = 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 _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 = 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: _objectSpread2(_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 = _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 = _objectSpread2(_objectSpread2(_objectSpread2({}, item), _detail), {}, {
						product_id: item.id,
						_id: item === null || item === void 0 ? void 0 : item._id,
						_key: e.key,
						_extend: _objectSpread2(_objectSpread2(_objectSpread2({}, item._extend), values), {}, { other }),
						new: 0
					});
					let _total = 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 = 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(_objectSpread2({ total: _total }, 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 = useMemoizedFn((e) => {
		if (state.channelDisabledEdit) return;
		dispatch({
			type: "setService",
			payload: {
				addModal: true,
				editModal: true,
				changeService: true
			}
		});
	});
	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.createElement(DatePicker, {
			className: "pisell-lowcode__booking-service-select-date",
			disabledDate: (current) => 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 = _asyncToGenerator(function* ({ start_date, end_date, duration }) {
			const cacheItem = yield getMultiDay({
				start_date,
				end_date,
				state,
				cacheItem: getCurrentCacheItem()
			});
			if (duration !== void 0) cacheItem._extend.duration = duration;
			cacheItem._extend.items = createBookingItemsByGroup(cacheItem);
			cacheItem._extend = _objectSpread2(_objectSpread2({}, cacheItem._extend), 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 = dayjs(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 = dayjs(changedValues === null || changedValues === void 0 ? void 0 : changedValues.start_date);
				const endDate = dayjs(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 = 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 = useMemo(() => {
		if (isEventBookingMode) return false;
		if (isDayBookingMode) return isDayBookingProduct(state.service.cacheItem, state);
		return true;
	}, [state.service.cacheItem, state.renderType]);
	const items = 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 = useMemo(() => {
		return items.length;
	}, [items]);
	const handleTotalChange = (number) => {
		isChangeTotal.current = true;
	};
	return useMemo(() => {
		var _state$service$cacheI8, _state$service9, _state$service$cacheI9, _state$service$cacheI10, _state$service$cacheI11, _state$service$cacheI12, _state$bookingConfig3;
		return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Drawer$2, {
			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 ? locales.getText("pisell2.text.edit-select-service") : 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.createElement("div", { className: "pisell-lowcode__booking-service-body-edit" }, isEditGroup ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Demo, {
			value: currentTab,
			onChange: (e) => {
				console.log(e);
				setCurrentTab(e);
			}
		}), /* @__PURE__ */ React.createElement("div", {
			className: "",
			style: { display: currentTab === "booking_list" ? "block" : "none" }
		}, /* @__PURE__ */ React.createElement(BookingList, { items }))) : null, /* @__PURE__ */ React.createElement("div", {
			className: "",
			style: { display: currentTab === "batch_edit" ? "block" : "none" }
		}, /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Page, null, /* @__PURE__ */ React.createElement(Form, {
			layout: "vertical",
			form,
			onFinish,
			onValuesChange
		}, /* @__PURE__ */ React.createElement(Row, {
			style: { width: "100%" },
			gutter: [16, 0]
		}, /* @__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" }, ((_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.createElement(Button, { onClick: handleEdit }, locales.getText("pisell2.text.edit")), !isTerminalBooking && /* @__PURE__ */ React.createElement(Button, { onClick: handleChange }, locales.getText("pisell2.text.change"))), /* @__PURE__ */ React.createElement(CollapsibleList, {
			style: { marginTop: bundles.length ? "8px" : 0 },
			list: bundles,
			renderItem: (item) => renderBundles(item, state.amountSymbol)
		})))), /* @__PURE__ */ React.createElement(Col, { span: 24 }, /* @__PURE__ */ React.createElement(Form.Item, {
			label: 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) && locales.getText("page.booking.text.price-extra")(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), formatAmount(useTotal, 2, state.amountSymbol))
		}, /* @__PURE__ */ React.createElement(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.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, showResource && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Col, { span: 12 }, /* @__PURE__ */ React.createElement(Form.Item, {
			label: 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.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.createElement(Col, { span: 12 }, /* @__PURE__ */ React.createElement(Form.Item, {
			label: locales.getText(isDayBookingMode ? "pisell2.text.end_date" : "pisell2.text.end_time"),
			name: "end_date",
			rules: [{ required: true }]
		}, DateCom("end"))) : null, /* @__PURE__ */ React.createElement(Col, { span: 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 })))), isDayBookingMode && (holderLists === null || holderLists === void 0 ? void 0 : holderLists.length) > 0 ? /* @__PURE__ */ React.createElement(Col, { span: isDayBookingMode ? 12 : 24 }, /* @__PURE__ */ React.createElement(Form.Item, {
			label: locales.getText("pisell2.text.holder"),
			name: "holder_id",
			rules: [{ required: isDayBookingMode }]
		}, /* @__PURE__ */ React.createElement(Holder, { size: "large" }))) : null, /* @__PURE__ */ React.createElement(Col, { span: 24 }, /* @__PURE__ */ React.createElement(Form.Item, {
			required: true,
			label: locales.getText("pisell2.text.resource")
		}, /* @__PURE__ */ React.createElement("div", { className: "resource-col" }, /* @__PURE__ */ React.createElement(Button, {
			className: "resource-col-like-wrap",
			disabled: !useResource,
			onClick: () => {
				handleLikeResource(useLikeStatus === "like" ? "common" : "like");
			}
		}, /* @__PURE__ */ React.createElement(Like, { status: useLikeStatus })), /* @__PURE__ */ React.createElement(Form.Item, {
			name: "resource",
			noStyle: true,
			rules: [{ required: true }]
		}, /* @__PURE__ */ React.createElement(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.createElement(Form.Item, {
			hidden: true,
			name: "quantity"
		}, /* @__PURE__ */ React.createElement(InputNumber, null)), /* @__PURE__ */ React.createElement(Form.Item, {
			hidden: true,
			name: "like_status"
		}, /* @__PURE__ */ React.createElement(Input, null))), !isEventBookingMode && isDayBookingMode && !isDayBookingProduct(state.service.cacheItem, state) ? /* @__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) => {
				if (value !== void 0) return Math.floor(value);
				return value;
			}
		}))) : null))), showResource && errorList.map((d, i) => {
			return /* @__PURE__ */ React.createElement(Alert, {
				key: d.type,
				message: d.label,
				type: "warning",
				showIcon: true,
				style: { marginBottom: 12 }
			});
		}))), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-service-body-edit-footer" }, /* @__PURE__ */ React.createElement("div", {
			className: "pisell-lowcode__booking-service-delete-wrap",
			onClick: handleDeleteProduct
		}, /* @__PURE__ */ React.createElement(Delete_wght300_24px, { className: "pisell-lowcode__booking-service-delete-icon" })), /* @__PURE__ */ React.createElement(Button, {
			type: "primary",
			className: "pisell-lowcode__booking-service-body-edit-footer-apple",
			disabled: resourceLoading,
			onClick: () => {
				form.submit();
			}
		}, 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,
		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 = forwardRef(Info);
//#endregion
export { editService_default as default };
