import { _objectSpread2 } from "../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { appointmentTypes } from "../../service2/status.js";
import CompensatedPisellContainer from "../../../../../pro/compensatedPisellContainer/index.js";
import withResponsive from "../../../../../responsive/withResponsive.js";
import React, { forwardRef, useImperativeHandle, useState } from "react";
import { Button } from "antd";
import { locales } from "@pisell/utils";
import "./index.less";
//#region src/components/booking/info/pet/ChangePetModal/index.tsx
const ChangePetModal = (props, ref) => {
	const { variant } = props;
	const [open, setOpen] = useState(false);
	const [params, setParams] = useState({});
	const isPhoneVariant = variant === "phone";
	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(CompensatedPisellContainer, {
		renderType: isPhoneVariant ? "drawer" : "modal",
		props: isPhoneVariant ? {
			open,
			placement: "bottom",
			width: "100%",
			height: "auto",
			title: null,
			onClose: () => handleProduct("cancel"),
			bodyStyle: { padding: 0 },
			className: "pisell2-change-pet-modal-drawer-phone",
			footer: /* @__PURE__ */ React.createElement("div", { style: {
				display: "flex",
				gap: 12
			} }, /* @__PURE__ */ React.createElement(Button, {
				style: { flex: 1 },
				onClick: () => handleProduct("cancel")
			}, locales.getText("pisell2.text.change.pet.cancel")), /* @__PURE__ */ React.createElement(Button, {
				style: { flex: 1 },
				type: "primary",
				onClick: () => handleProduct("ok")
			}, locales.getText("pisell2.text.change.pet.confirm")))
		} : {
			open,
			platform: "pc",
			width: 432,
			title: locales.getText("pisell2.text.change.pet.title"),
			onCancel: () => handleProduct("cancel"),
			footer: /* @__PURE__ */ React.createElement("div", { style: {
				display: "flex",
				justifyContent: "flex-end",
				gap: 8
			} }, /* @__PURE__ */ React.createElement(Button, { onClick: () => handleProduct("cancel") }, locales.getText("pisell2.text.change.pet.cancel")), /* @__PURE__ */ React.createElement(Button, {
				type: "primary",
				onClick: () => handleProduct("ok")
			}, locales.getText("pisell2.text.change.pet.confirm"))),
			closable: true
		}
	}, /* @__PURE__ */ React.createElement("div", { className: "pisell2-change-pet-modal-phone-panel" }, isPhoneVariant ? /* @__PURE__ */ React.createElement("div", { className: "pisell2-change-pet-modal-phone-title" }, locales.getText("pisell2.text.change.pet.title")) : null, /* @__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")))));
};
const ForwardedChangePetModal = forwardRef(ChangePetModal);
ForwardedChangePetModal.displayName = "ChangePetModal";
var ChangePetModal_default = withResponsive(ForwardedChangePetModal);
//#endregion
export { ChangePetModal_default as default };
