var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/pisellReservation/components/bookingDetailModal/ReservationBookingDetailModal.tsx
var ReservationBookingDetailModal_exports = {};
__export(ReservationBookingDetailModal_exports, {
  ReservationBookingDetailModal: () => ReservationBookingDetailModal
});
module.exports = __toCommonJS(ReservationBookingDetailModal_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_editBookingModal = __toESM(require("../../../../components/booking/editBookingModal"));
var import_compensatedPisellContainer = __toESM(require("../../../../pro/compensatedPisellContainer"));
var import_floorRoomCard = require("../../floorRoomCard");
var import_reservationTicketBookingHostParams = require("../../utils/reservationTicketBookingHostParams");
var import_BookingDetailUnit = require("./BookingDetailUnit");
var import_bookingDetailModalConstants = require("./bookingDetailModalConstants");
var import_bookingDetailResourceBookingItem = require("./bookingDetailResourceBookingItem");
var import_useBookingDetailActions = require("./useBookingDetailActions");
var import_ReservationBookingDetailModal = require("./ReservationBookingDetailModal.less");
function ReservationBookingDetailModal(props) {
  var _a;
  const {
    open,
    onClose,
    onActionSuccess,
    raw,
    tableRow,
    sceneElementName,
    reservationBiz,
    associatedMenuListIds,
    reservationRuleProduct,
    floorDayBookingList,
    currentTime,
    followWallClock,
    singleBookingMode
  } = props;
  const [activeTab, setActiveTab] = (0, import_react.useState)("current-occupied");
  const engineContext = (0, import_useEngineContext.default)();
  const appHelperUtils = (_a = engineContext == null ? void 0 : engineContext.appHelper) == null ? void 0 : _a.utils;
  const {
    resourceBookingItem,
    resourceBookingItemLoading,
    activeTabBookings
  } = (0, import_bookingDetailResourceBookingItem.useResourceBookingItem)(activeTab, {
    open,
    raw,
    tableRow,
    floorDayBookingList,
    currentTime,
    followWallClock,
    pisellos: appHelperUtils == null ? void 0 : appHelperUtils.pisellos,
    disabled: singleBookingMode
  });
  const tabCounts = (0, import_react.useMemo)(() => {
    if (resourceBookingItem == null) return null;
    return {
      "current-occupied": resourceBookingItem.bookings.length,
      ended: resourceBookingItem.completedBookings.length,
      unpaid: resourceBookingItem.unpaidBookings.length
    };
  }, [resourceBookingItem]);
  const {
    editBookingModalRef,
    isCancellingOrder,
    isCompletingBooking,
    handleResourceChangeConfirmed,
    handleActionCellClick
  } = (0, import_useBookingDetailActions.useBookingDetailActions)({
    raw,
    tableRow,
    reservationBiz,
    associatedMenuListIds,
    onActionSuccess,
    appHelperUtils
  });
  (0, import_react.useEffect)(() => {
    setActiveTab("current-occupied");
  }, [raw == null ? void 0 : raw.id, raw == null ? void 0 : raw.booking_uid, raw == null ? void 0 : raw.booking_id]);
  const detailModalTitle = (0, import_react.useMemo)(() => {
    var _a2;
    if (tableRow == null) {
      return import_utils.locales.getText(`${import_bookingDetailModalConstants.I18N_BD}.modal-title`);
    }
    const scene = sceneElementName != null && String(sceneElementName).trim() !== "" ? String(sceneElementName).trim() : void 0;
    const roomTitle = (0, import_floorRoomCard.displayRoomTitleFromRow)(tableRow, scene).trim();
    const code = (_a2 = tableRow.code) == null ? void 0 : _a2.trim();
    const baseTitle = roomTitle || code || import_utils.locales.getText(import_bookingDetailModalConstants.I18N_ROOM_KIND_BOUND);
    return (0, import_floorRoomCard.appendBookingCountSuffix)(baseTitle, tableRow);
  }, [tableRow, sceneElementName]);
  const canShow = Boolean(open && raw != null);
  const handleHeaderCloseClick = (0, import_react.useCallback)(
    (e) => {
      (0, import_bookingDetailModalConstants.stopUiClick)(e);
      onClose(e);
    },
    [onClose]
  );
  const handleHeaderNewOrderClick = (0, import_react.useCallback)(
    (e) => {
      (0, import_bookingDetailModalConstants.stopUiClick)(e);
      (0, import_reservationTicketBookingHostParams.openNewReservationBookingFromHost)({
        appHelperUtils,
        reservationBiz,
        associatedMenuListIds,
        reservationRuleProduct,
        row: tableRow ?? null
      });
    },
    [
      appHelperUtils,
      reservationBiz,
      associatedMenuListIds,
      reservationRuleProduct,
      tableRow
    ]
  );
  const detailModalHeader = (0, import_react.useMemo)(
    () => /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_bookingDetailModalConstants.PREFIX}__header` }, /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        type: "button",
        className: `${import_bookingDetailModalConstants.PREFIX}__header-action ${import_bookingDetailModalConstants.PREFIX}__header-action--left`,
        onClick: handleHeaderCloseClick
      },
      (0, import_bookingDetailModalConstants.t)("header-close")
    ), /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_bookingDetailModalConstants.PREFIX}__header-title` }, detailModalTitle), /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        type: "button",
        className: `${import_bookingDetailModalConstants.PREFIX}__header-action ${import_bookingDetailModalConstants.PREFIX}__header-action--right`,
        onClick: handleHeaderNewOrderClick
      },
      (0, import_bookingDetailModalConstants.t)("header-new-order")
    )),
    [detailModalTitle, handleHeaderCloseClick, handleHeaderNewOrderClick]
  );
  const getApp = appHelperUtils == null ? void 0 : appHelperUtils.getApp;
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_compensatedPisellContainer.default,
    {
      renderType: "modal",
      props: {
        platform: "pc",
        open: canShow,
        onCancel: onClose,
        maskProps: import_bookingDetailModalConstants.BD_MODAL_MASK,
        focusTriggerAfterClose: false,
        title: detailModalHeader,
        closable: false,
        footer: null,
        destroyOnClose: true,
        width: 560,
        wrapClassName: `${import_bookingDetailModalConstants.PREFIX}-wrap pisell-pc-modal`
      }
    },
    raw ? /* @__PURE__ */ import_react.default.createElement("div", { className: import_bookingDetailModalConstants.PREFIX }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_bookingDetailModalConstants.PREFIX}__body` }, singleBookingMode ? (
      /**
       * 单条预约模式：日历入口已经在 `raw` 上唯一指向某条预约，
       * 不再走宿主 `getResourceBookingItem` 聚合，也不渲染三个 Tab，
       * 直接展示该条 booking 的 RoomCard + 操作栏 + 商品。
       */
      /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: `${import_bookingDetailModalConstants.PREFIX}__bookings-list`,
          role: "tabpanel",
          "aria-label": (0, import_bookingDetailModalConstants.t)("tab-current-occupied")
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_BookingDetailUnit.BookingDetailUnit,
          {
            bookingRaw: raw,
            tableRow,
            isCancellingOrder,
            isCompletingBooking,
            getApp,
            onActionCellClick: handleActionCellClick
          }
        )
      )
    ) : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: `${import_bookingDetailModalConstants.PREFIX}__tabs`,
        role: "tablist",
        "aria-label": (0, import_bookingDetailModalConstants.t)("tabs-aria")
      },
      import_bookingDetailModalConstants.DETAIL_TAB_ITEMS.map(({ key, labelKey }) => {
        const active = activeTab === key;
        const count = tabCounts == null ? void 0 : tabCounts[key];
        return /* @__PURE__ */ import_react.default.createElement(
          "button",
          {
            key,
            type: "button",
            role: "tab",
            "aria-selected": active,
            className: `${import_bookingDetailModalConstants.PREFIX}__tab${active ? ` ${import_bookingDetailModalConstants.PREFIX}__tab--active` : ""}`,
            onClick: (e) => {
              (0, import_bookingDetailModalConstants.stopUiClick)(e);
              setActiveTab(key);
            }
          },
          (0, import_bookingDetailModalConstants.t)(labelKey),
          count != null ? /* @__PURE__ */ import_react.default.createElement("span", { className: `${import_bookingDetailModalConstants.PREFIX}__tab-count` }, " ", "(", count, ")") : null
        );
      })
    ), /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: `${import_bookingDetailModalConstants.PREFIX}__bookings-list`,
        role: "tabpanel",
        "aria-label": (0, import_bookingDetailModalConstants.t)(`tab-${activeTab}`)
      },
      activeTabBookings.length === 0 ? !resourceBookingItemLoading ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_bookingDetailModalConstants.PREFIX}__bookings-empty` }, (0, import_bookingDetailModalConstants.t)("empty-tab-bookings")) : null : activeTabBookings.map((bookingRaw, idx) => {
        const unitKey = String(
          bookingRaw.id ?? bookingRaw.booking_uid ?? bookingRaw.booking_id ?? idx
        );
        return /* @__PURE__ */ import_react.default.createElement(
          import_BookingDetailUnit.BookingDetailUnit,
          {
            key: unitKey,
            bookingRaw,
            tableRow,
            isCancellingOrder,
            isCompletingBooking,
            getApp,
            onActionCellClick: handleActionCellClick
          }
        );
      })
    )))) : null
  ), /* @__PURE__ */ import_react.default.createElement(
    import_editBookingModal.default,
    {
      ref: editBookingModalRef,
      open: false,
      onCancel: () => {
      },
      onOk: handleResourceChangeConfirmed
    }
  ));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ReservationBookingDetailModal
});
