const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_useComponents = require("../../../../hooks/useComponents.js");
const require_utils = require("../../utils.js");
const require_context = require("../../context.js");
const require_hooks = require("../../hooks.js");
const require_utils$1 = require("./utils.js");
let react = require("react");
react = require_runtime.__toESM(react);
require("./index.less");
//#region src/components/appointmentBooking/components/Form/index.tsx
const Form = (0, react.forwardRef)((props, ref) => {
	const manualRef = (0, react.useRef)();
	const { appointmentBooking, setLoading, currentStepParams, carts } = require_context.useAppointmentBookingContext();
	const { getResourceList } = require_hooks.useAppointmentBookingResource();
	const { setOtherData, getOtherData, isFormSubject } = require_hooks.useAppointmentBookingSetting();
	const { nextStep } = require_hooks.useAppointmentBookingStep();
	const { isLogin } = require_hooks.useAppointmentBookingLogin();
	const { checkAccount } = require_hooks.useAppointmentBookingAccount();
	(0, react.useImperativeHandle)(ref, () => ({ next: () => {
		var _stepLists, _manualRef$current, _manualRef$current$su;
		(_stepLists = ((currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.stepLists) || [])[(currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.index) + 1]) === null || _stepLists === void 0 || _stepLists.key;
		setLoading(true);
		(_manualRef$current = manualRef.current) === null || _manualRef$current === void 0 || (_manualRef$current$su = _manualRef$current.submit) === null || _manualRef$current$su === void 0 || _manualRef$current$su.call(_manualRef$current);
	} }));
	const [FormCard] = require_useComponents.default({ components: ["FormCard"] });
	const key = "booking_form";
	const formStorage = getOtherData("booking_form") || {};
	const appointmentBoard = (0, react.useMemo)(() => {
		const { resources } = getResourceList();
		return require_utils.currentAppointmentBoard(currentStepParams.key, resources, appointmentBooking);
	}, [currentStepParams.key]);
	const formId = (0, react.useMemo)(() => {
		return (appointmentBoard === null || appointmentBoard === void 0 ? void 0 : appointmentBoard.resource_form_id) || 0;
	}, [appointmentBoard === null || appointmentBoard === void 0 ? void 0 : appointmentBoard.resource_form_id]);
	/**
	* @title: 更新表单状态
	* @description:
	* @param {string} status
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-04-26 18:39
	*/
	const updateFormStatus = (status) => {
		if (status === "error") setLoading(false);
	};
	/**
	* @title: 设置表单存储
	* @description:
	* @param {any} values
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-04-28 11:32
	*/
	const setFormStorage = (values) => {
		setOtherData(key, require_objectSpread2._objectSpread2({}, require_utils.updateBookingFormStorage(getOtherData(key), currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.key, values)));
		appointmentBooking.updateCart({
			_id: appointmentBoard === null || appointmentBoard === void 0 ? void 0 : appointmentBoard.cart_id,
			relationForms: require_utils$1.updateRelationForms(carts, appointmentBoard, values, currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.key)
		});
	};
	/**
	* @title: 表单设置成功之后的提交
	* @description:
	* @param {string} status
	* @param {any} values
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-04-28 11:34
	*/
	const handleFormFinish = (status, values) => {
		try {
			updateFormStatus(status);
			if (status === "success") {
				setFormStorage(values);
				nextStep();
			}
		} catch (error) {
			setLoading(false);
		}
	};
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", {
		className: "appointment-form-wrap",
		key: currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.key
	}, /* @__PURE__ */ react.default.createElement(FormCard, {
		id: formId,
		ref: manualRef,
		isGetLastData: false,
		setting: { isHidden: 1 },
		formWrapStyle: { padding: "16px" },
		isV2API: true,
		isShowSkeleton: true,
		onSubmit: (status, values) => {
			handleFormFinish(status, values);
		},
		onFinishFailed: (e) => {
			updateFormStatus("error");
		},
		onFormValueChange: (values) => {},
		defaultValues: (formStorage === null || formStorage === void 0 ? void 0 : formStorage[currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.key]) || {},
		isClearData: false
	})));
});
//#endregion
exports.default = Form;
