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/BookingDetailUnit.tsx
var BookingDetailUnit_exports = {};
__export(BookingDetailUnit_exports, {
  BookingDetailUnit: () => BookingDetailUnit
});
module.exports = __toCommonJS(BookingDetailUnit_exports);
var import_react = __toESM(require("react"));
var import_icons = require("@ant-design/icons");
var import_materials = require("@pisell/materials");
var import_floorRoomCard = require("../../floorRoomCard");
var import_bookingProductToProductCard = require("./bookingProductToProductCard");
var import_bookingDetailHostActions = require("./bookingDetailHostActions");
var import_bookingDetailModalConstants = require("./bookingDetailModalConstants");
var BASE_ACTION_ITEMS = [
  { key: "action-edit", icon: /* @__PURE__ */ import_react.default.createElement(import_icons.EditOutlined, null) },
  { key: "action-cart", icon: /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-coins-hand" }) },
  { key: "action-print", icon: /* @__PURE__ */ import_react.default.createElement(import_icons.PrinterOutlined, null) },
  { key: "action-list", icon: /* @__PURE__ */ import_react.default.createElement(import_icons.UnorderedListOutlined, null) }
];
function buildActionItems(status, bookingRaw) {
  const completed = (0, import_bookingDetailHostActions.isCompletedBookingRaw)(bookingRaw);
  const statusAction = completed ? null : status === "occupied" ? {
    key: "action-complete",
    icon: /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-check-square-broken" })
  } : {
    key: "action-start",
    icon: /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-send-01" })
  };
  return [
    BASE_ACTION_ITEMS[1],
    BASE_ACTION_ITEMS[0],
    { key: "action-form", icon: /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-edit-05" }) },
    ...statusAction ? [statusAction] : [],
    ...BASE_ACTION_ITEMS.slice(2),
    { key: "action-close", icon: /* @__PURE__ */ import_react.default.createElement(import_icons.CloseCircleOutlined, null) }
  ];
}
function BookingDetailUnit(props) {
  const {
    bookingRaw,
    tableRow,
    isCancellingOrder,
    isCompletingBooking,
    getApp,
    onActionCellClick
  } = props;
  const data = (0, import_react.useMemo)(
    () => (0, import_floorRoomCard.buildDetailModalRoomCardData)(bookingRaw, tableRow ?? null),
    [bookingRaw, tableRow]
  );
  const headerOverride = (0, import_react.useMemo)(
    () => (0, import_floorRoomCard.resolveBookingIdForHeader)(bookingRaw),
    [bookingRaw]
  );
  const statusTag = (0, import_react.useMemo)(
    () => (0, import_bookingDetailHostActions.resolveAppointmentStatusTag)(bookingRaw),
    [bookingRaw]
  );
  const isCompleted = (0, import_react.useMemo)(
    () => (0, import_bookingDetailHostActions.isCompletedBookingRaw)(bookingRaw),
    [bookingRaw]
  );
  const items = (0, import_react.useMemo)(
    () => buildActionItems(data == null ? void 0 : data.status, bookingRaw),
    [data == null ? void 0 : data.status, bookingRaw]
  );
  const productSources = (0, import_react.useMemo)(
    () => (0, import_bookingDetailHostActions.parseBookingProducts)(bookingRaw).map(
      (line, i) => (0, import_bookingProductToProductCard.bookingProductLineToProductCardData)(line, i, { app: getApp == null ? void 0 : getApp() })
    ),
    [bookingRaw, getApp]
  );
  const symbol = (0, import_react.useMemo)(
    () => (0, import_bookingDetailHostActions.orderCurrencySymbol)(
      bookingRaw.order
    ),
    [bookingRaw.order]
  );
  return /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_bookingDetailModalConstants.PREFIX}__booking-card` }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `${import_bookingDetailModalConstants.PREFIX}__room-card-slot pisell-res-floor-room-card`,
      onMouseDown: import_bookingDetailModalConstants.stopUiClick,
      onClick: import_bookingDetailModalConstants.stopUiClick
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_floorRoomCard.FloorRoomCardFromData,
      {
        data,
        shellShape: "rect",
        hideHeader: true,
        hideHeaderCapacity: true,
        headerMainFieldOverride: headerOverride,
        bodyStatusTag: statusTag
      }
    )
  ), /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: isCompleted ? `${import_bookingDetailModalConstants.PREFIX}__action-grid ${import_bookingDetailModalConstants.PREFIX}__action-grid--cols-3` : `${import_bookingDetailModalConstants.PREFIX}__action-grid`,
      role: "group",
      "aria-label": (0, import_bookingDetailModalConstants.t)("action-grid-aria")
    },
    items.map(({ key: ak, icon }) => {
      const tintClass = (0, import_bookingDetailModalConstants.bookingDetailActionCellTintClass)(ak);
      return /* @__PURE__ */ import_react.default.createElement(
        "button",
        {
          key: ak,
          type: "button",
          className: tintClass ? `${import_bookingDetailModalConstants.PREFIX}__action-cell ${tintClass}` : `${import_bookingDetailModalConstants.PREFIX}__action-cell`,
          disabled: ak === "action-close" && isCancellingOrder || ak === "action-complete" && isCompletingBooking,
          onClick: (ev) => onActionCellClick(bookingRaw, ak, ev)
        },
        import_react.default.isValidElement(icon) ? import_react.default.cloneElement(icon, {
          className: `${import_bookingDetailModalConstants.PREFIX}__action-icon`,
          "aria-hidden": true
        }) : null,
        /* @__PURE__ */ import_react.default.createElement("span", { className: `${import_bookingDetailModalConstants.PREFIX}__action-label` }, (0, import_bookingDetailModalConstants.t)(ak))
      );
    })
  ), /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_bookingDetailModalConstants.PREFIX}__products-section` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_bookingDetailModalConstants.PREFIX}__products-list` }, productSources.length === 0 ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_bookingDetailModalConstants.PREFIX}__products-empty` }, (0, import_bookingDetailModalConstants.t)("empty-items")) : productSources.map((ds) => /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      key: String(ds._id),
      className: `${import_bookingDetailModalConstants.PREFIX}__product-card-slot`
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_materials.ProductCard,
      {
        dataSource: { ...ds, symbol },
        isShowImage: false,
        isShowHolder: false,
        isShowNote: false,
        isShowDelete: false,
        isShowPackageNote: false,
        isShowEditProduct: false
      }
    )
  )))));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  BookingDetailUnit
});
