import { _objectSpread2 } from "../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { appointmentTypes } from "../../service2/status.js";
import React, { forwardRef, useImperativeHandle, useState } from "react";
import { locales } from "@pisell/utils";
import { PisellModal } from "@pisell/materials";
import "./index.less";
//#region src/components/booking/info/pet/ChangePetModal/index.tsx
const ChangePetModal = (props, ref) => {
	const [open, setOpen] = useState(false);
	const [params, setParams] = useState({});
	useImperativeHandle(ref, () => ({ open: (e) => {
		setParams(e);
		setOpen(true);
	} }));
	/**
	* @title: 确认之后的操作
	* @description:
	* @param {string} type
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-12 22:56
	*/
	const handleProduct = (type) => {
		const { ids, service, dispatch, setGlobalState, state, source } = params;
		let _service = [...service || []];
		if (source === "changeClient") if (type === "ok") _service = _service === null || _service === void 0 ? void 0 : _service.filter((item) => !appointmentTypes.includes(item.extension_type));
		else _service = [];
		else if (type === "ok") {
			_service = _service === null || _service === void 0 ? void 0 : _service.map((item) => {
				if (ids === null || ids === void 0 ? void 0 : ids.includes(item._extend.holder_id)) return _objectSpread2(_objectSpread2({}, item), {}, { _extend: _objectSpread2(_objectSpread2({}, item._extend || {}), {}, { holder_id: 0 }) });
				return item;
			});
			_service = _service.filter((item) => {
				var _item$_extend;
				return !((item === null || item === void 0 || (_item$_extend = item._extend) === null || _item$_extend === void 0 ? void 0 : _item$_extend.holder_id) === 0 && appointmentTypes.includes(item.extension_type));
			});
		} else _service = _service.filter((item) => !ids.includes(item._extend.holder_id));
		if (dispatch) dispatch({
			type: "setService",
			payload: {
				value: [..._service],
				edit: true
			}
		});
		else setGlobalState({ service: _objectSpread2(_objectSpread2({}, state.service), {}, {
			edit: true,
			value: [..._service]
		}) });
		setOpen(false);
	};
	return /* @__PURE__ */ React.createElement(PisellModal.Information, {
		open,
		platform: "pc",
		width: 432,
		title: locales.getText("pisell2.text.change.pet.title"),
		describe: /* @__PURE__ */ React.createElement("div", { className: "pisell2-change-pet-modal-content" }, /* @__PURE__ */ React.createElement("span", null, locales.getText("pisell2.text.change.pet.content")), /* @__PURE__ */ React.createElement("span", null, locales.getText("pisell2.text.change.pet.content1"))),
		cancelText: locales.getText("pisell2.text.change.pet.cancel"),
		okText: locales.getText("pisell2.text.change.pet.confirm"),
		closable: true,
		onOk: () => handleProduct("ok"),
		onCancel: () => handleProduct("cancel")
	});
};
var ChangePetModal_default = forwardRef(ChangePetModal);
//#endregion
export { ChangePetModal_default as default };
