const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_reservationConstants = require("../reservationConstants.js");
const require_useNewReservationRoutesFromEngine = require("../hooks/useNewReservationRoutesFromEngine.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let ahooks = require("ahooks");
//#region src/plus/pisellReservation/components/ReservationNewReservationModal.tsx
/**
* 新建预约：引擎路由多选弹窗；仅单条路由时直接 history.push。
*/
/**
* 受控弹窗内容在内部；通过 ref 暴露 `requestOpen` 供顶栏「新建」等调用。
*/
const ReservationNewReservationModal = (0, react.forwardRef)(function ReservationNewReservationModal({ router, app }, ref) {
	const newReservationRoutes = require_useNewReservationRoutesFromEngine.useNewReservationRoutesFromEngine(router);
	const [open, setOpen] = (0, react.useState)(false);
	const handleRouteJump = (0, ahooks.useMemoizedFn)((routePath) => {
		var _app$history, _app$history$push;
		if (!routePath) return;
		setOpen(false);
		app === null || app === void 0 || (_app$history = app.history) === null || _app$history === void 0 || (_app$history$push = _app$history.push) === null || _app$history$push === void 0 || _app$history$push.call(_app$history, routePath);
	});
	const requestOpen = (0, ahooks.useMemoizedFn)(() => {
		if (newReservationRoutes.length === 1) {
			handleRouteJump(newReservationRoutes[0].router);
			return;
		}
		setOpen(true);
	});
	(0, react.useImperativeHandle)(ref, () => ({ requestOpen }), [requestOpen]);
	const handleClose = (0, ahooks.useMemoizedFn)(() => {
		setOpen(false);
	});
	return /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellModal, {
		platform: "pc",
		open,
		title: _pisell_utils.locales.getText(require_reservationConstants.I18N_NEW_MODAL_TITLE),
		onCancel: handleClose,
		maskClosable: true,
		footer: null,
		width: 520,
		wrapClassName: "pisell-reservation-new-modal-wrap",
		destroyOnClose: true
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-new-modal-placeholder" }, newReservationRoutes.length > 0 ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-new-modal-route-list" }, newReservationRoutes.map((routeItem) => /* @__PURE__ */ react.default.createElement("button", {
		key: `${routeItem.router}-${routeItem.pageName}`,
		type: "button",
		className: "pisell-reservation-new-modal-route-item",
		onClick: () => handleRouteJump(routeItem.router)
	}, /* @__PURE__ */ react.default.createElement("span", { className: "pisell-reservation-new-modal-route-name" }, routeItem.pageName), /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, {
		type: "icon-right-arrow",
		className: "pisell-reservation-new-modal-route-arrow"
	})))) : /* @__PURE__ */ react.default.createElement("p", { className: "pisell-reservation-new-modal-empty" }, _pisell_utils.locales.getText(require_reservationConstants.I18N_NEW_MODAL_PLACEHOLDER))));
});
//#endregion
exports.ReservationNewReservationModal = ReservationNewReservationModal;
