const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_index = require("../../../../businessModel/SalesModel/Sales/index.js");
const require_index$1 = require("../../../Sales/Step/index.js");
const require_index$2 = require("../../../Sales/Cart/index.js");
const require_index$3 = require("../../../Sales/Holder/index.js");
const require_index$4 = require("../selectHolder/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
//#region src/components/eventBooking/components/Provider/SelectHolderModal.tsx
const SelectHolderModal = (props) => {
	var _holderData$holderLis;
	const { open } = props;
	const { data } = require_index.useSales();
	const { onHolderClose, onOpenCreateHolder, selectHolder, holderData, updateHolderList, defaultSelectedHolder } = require_index$3.useHolder();
	const { nextStep, prevStep, currentStepData } = require_index$1.useStep();
	const [selectedHolder, setSelectedHolder] = (0, react.useState)(defaultSelectedHolder);
	const { onCloseCart } = require_index$2.useCart();
	(0, react.useEffect)(() => {
		setSelectedHolder(defaultSelectedHolder);
	}, [defaultSelectedHolder]);
	/**
	* @title: 点击holder卡片
	* @description:
	* @param {any} e
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-16 22:29
	*/
	const handleHolder = (e) => {
		var _data$initData;
		if (!(e === null || e === void 0 ? void 0 : e.isAddCard)) {
			setSelectedHolder(e);
			return;
		}
		onOpenCreateHolder({
			form_id: (_data$initData = data.initData) === null || _data$initData === void 0 || (_data$initData = _data$initData.boardSetting) === null || _data$initData === void 0 || (_data$initData = _data$initData.config) === null || _data$initData === void 0 || (_data$initData = _data$initData.basic) === null || _data$initData === void 0 || (_data$initData = _data$initData.appointment_subject) === null || _data$initData === void 0 ? void 0 : _data$initData.form_id,
			form_title: _pisell_utils.locales.getText("pisell2.event.create.form"),
			callback: (res) => {
				updateHolderList(res === null || res === void 0 ? void 0 : res.values);
			}
		});
	};
	return /* @__PURE__ */ react.default.createElement(require_index$4.default, {
		open,
		options: (holderData === null || holderData === void 0 ? void 0 : holderData.holderList) || [],
		onCancel: () => onHolderClose(),
		value: selectedHolder === null || selectedHolder === void 0 ? void 0 : selectedHolder.id,
		title: _pisell_utils.locales.getText("pisell2.event.holder.modal.title"),
		okText: _pisell_utils.locales.getText("pisell2.event.confirm"),
		onClick: (e) => handleHolder(e),
		disabled: !(holderData === null || holderData === void 0 || (_holderData$holderLis = holderData.holderList) === null || _holderData$holderLis === void 0 ? void 0 : _holderData$holderLis.length) || !(selectedHolder === null || selectedHolder === void 0 ? void 0 : selectedHolder.id),
		errorTipText: _pisell_utils.locales.getText("pisell2.event.error.holder"),
		onOk: () => {
			onCloseCart();
			const isEvent = (currentStepData === null || currentStepData === void 0 ? void 0 : currentStepData.key) === "select-event";
			selectHolder(selectedHolder, isEvent ? "addToCart" : "createCartItem");
			if (isEvent) nextStep();
			else prevStep();
			onHolderClose();
		}
	});
};
//#endregion
exports.default = SelectHolderModal;
