const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_utils = require("../../utils.js");
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");
require("./index.less");
//#region src/components/shoppingCart/components/SelectHolderModal/index.tsx
const SelectPetModal = ({ onChange }, ref) => {
	const [open, setOpen] = (0, react.useState)(false);
	const [params, setParams] = (0, react.useState)(null);
	(0, react.useImperativeHandle)(ref, () => {
		return { open: ({ products, holders }) => {
			var _holders$;
			const _holders = holders === null || holders === void 0 ? void 0 : holders.filter((item) => item.key > 0);
			setParams({
				service: require_utils.formatService(products, _holders === null || _holders === void 0 || (_holders$ = _holders[0]) === null || _holders$ === void 0 ? void 0 : _holders$.key),
				holders: _holders
			});
			setOpen(true);
		} };
	});
	const handleChange = (e, index) => {
		const _lists = [...params === null || params === void 0 ? void 0 : params.service];
		_lists[index].holder_id = e;
		console.log(e, index, _lists, "wh79876");
		setParams(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, params), {}, { service: _lists }));
	};
	/**
	* @title: 弹窗内容
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-03 16:26
	*/
	const content = (0, react.useMemo)(() => {
		var _params$holders;
		const services = (params === null || params === void 0 ? void 0 : params.service) || [];
		const options = params === null || params === void 0 || (_params$holders = params.holders) === null || _params$holders === void 0 ? void 0 : _params$holders.map((item) => {
			return {
				value: item.key,
				label: item.main_field
			};
		});
		return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__booking-select-pet-content" }, services === null || services === void 0 ? void 0 : services.map((item, index) => {
			var _options$;
			return /* @__PURE__ */ react.default.createElement("div", {
				className: "pisell-lowcode__booking-select-pet-item",
				key: item._id
			}, /* @__PURE__ */ react.default.createElement("span", null, " ", item.name), /* @__PURE__ */ react.default.createElement(antd.Select, {
				defaultValue: (_options$ = options[0]) === null || _options$ === void 0 ? void 0 : _options$.value,
				onChange: (e) => handleChange(e, index),
				options,
				popupMatchSelectWidth: false
			}));
		}));
	}, [params === null || params === void 0 ? void 0 : params.service, params === null || params === void 0 ? void 0 : params.pets]);
	const handleCancel = () => {
		setOpen(false);
	};
	/**
	* @title: 点击确定
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-03 17:05
	*/
	const handleOk = () => {
		const { service } = params;
		onChange(service, "update_holders", service === null || service === void 0 ? void 0 : service.map((item) => {
			return {
				_id: item._id,
				holder_id: item.holder_id
			};
		}));
		handleCancel();
	};
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellModal, {
		platform: "pc",
		open,
		bodyStyle: { padding: 0 },
		title: _pisell_utils.locales.getText("pisell2.text.shopping-cart.select.holder.modal.title"),
		okText: _pisell_utils.locales.getText("pisell2.text.shopping-cart.confirm"),
		cancelText: _pisell_utils.locales.getText("pisell2.text.shopping-cart.cancel"),
		onCancel: handleCancel,
		onOk: handleOk,
		destroyOnClose: true,
		className: "pisell-lowcode__booking-select-pet-modal-wrap"
	}, content));
};
var SelectHolderModal_default = (0, react.forwardRef)(SelectPetModal);
//#endregion
exports.default = SelectHolderModal_default;
