function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/**
 * 新建预约：引擎路由多选弹窗；仅单条路由时直接 history.push。
 */
import React, { forwardRef, useImperativeHandle, useState } from 'react';
import { useMemoizedFn } from 'ahooks';
import { PisellModal, Icon } from '@pisell/materials';
import { locales } from '@pisell/utils';
import { useNewReservationRoutesFromEngine } from "../hooks/useNewReservationRoutesFromEngine";
import { I18N_NEW_MODAL_PLACEHOLDER, I18N_NEW_MODAL_TITLE } from "../reservationConstants";
/**
 * 受控弹窗内容在内部；通过 ref 暴露 `requestOpen` 供顶栏「新建」等调用。
 */
export var ReservationNewReservationModal = /*#__PURE__*/forwardRef(function ReservationNewReservationModal(_ref, ref) {
  var router = _ref.router,
    app = _ref.app;
  var newReservationRoutes = useNewReservationRoutesFromEngine(router);
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    open = _useState2[0],
    setOpen = _useState2[1];
  var handleRouteJump = useMemoizedFn(function (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);
  });
  var requestOpen = useMemoizedFn(function () {
    if (newReservationRoutes.length === 1) {
      handleRouteJump(newReservationRoutes[0].router);
      return;
    }
    setOpen(true);
  });
  useImperativeHandle(ref, function () {
    return {
      requestOpen: requestOpen
    };
  }, [requestOpen]);
  var handleClose = useMemoizedFn(function () {
    setOpen(false);
  });
  return /*#__PURE__*/React.createElement(PisellModal, {
    platform: "pc",
    open: 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(function (routeItem) {
    return /*#__PURE__*/React.createElement("button", {
      key: "".concat(routeItem.router, "-").concat(routeItem.pageName),
      type: "button",
      className: "pisell-reservation-new-modal-route-item",
      onClick: function onClick() {
        return 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))));
});