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