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/SelectFloorMapResourceDialog.tsx
var SelectFloorMapResourceDialog_exports = {};
__export(SelectFloorMapResourceDialog_exports, {
  SelectFloorMapResourceDialog: () => SelectFloorMapResourceDialog,
  default: () => SelectFloorMapResourceDialog_default
});
module.exports = __toCommonJS(SelectFloorMapResourceDialog_exports);
var import_react = __toESM(require("react"));
var import_dayjs = __toESM(require("dayjs"));
var import_antd = require("antd");
var import_utils = require("@pisell/utils");
var import_compensatedPisellContainer = __toESM(require("../../../pro/compensatedPisellContainer"));
var import_PisellReservation = require("../PisellReservation");
var import_reservationConstants = require("../reservationConstants");
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var import_SelectFloorMapResourceDialog = require("./SelectFloorMapResourceDialog.less");
var I18N_TITLE = "pisell-reservation.select-resource.title";
var DIALOG_WIDTH = "99%";
var DIALOG_BODY_STYLE = { padding: 0, height: "100%" };
var CONTENT_RENDER_DELAY = 200;
function SelectFloorMapResourceSkeleton() {
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-select-floor-map-resource-dialog-skeleton" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-select-floor-map-resource-dialog-skeleton__toolbar" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Skeleton.Button, { active: true, block: true }), /* @__PURE__ */ import_react.default.createElement(import_antd.Skeleton.Button, { active: true, block: true }), /* @__PURE__ */ import_react.default.createElement(import_antd.Skeleton.Button, { active: true, block: true })));
}
function normalizeScheduleValue(value) {
  if (value == null) return void 0;
  const rawAt = typeof value === "string" ? value : value.at;
  const at = (0, import_dayjs.default)(rawAt);
  if (!at.isValid()) return void 0;
  const rawDate = typeof value === "string" ? void 0 : value.date;
  const parsedDate = (0, import_dayjs.default)(rawDate);
  const date = rawDate != null && parsedDate.isValid() ? parsedDate.startOf("day") : at.startOf("day");
  return { date, at };
}
function SelectFloorMapResourceDialog({
  open,
  onClose,
  onClick,
  reservationBiz,
  businessCode,
  associatedMenuListIds,
  scheduleValue,
  floorPlanId,
  floorPlanCode,
  floorPlanCanvasWidth,
  floorPlanCanvasHeight,
  dataSources,
  floorMap,
  title
}) {
  var _a, _b;
  const engineCtx = (0, import_useEngineContext.default)();
  const engineLocale = ((_b = (_a = engineCtx == null ? void 0 : engineCtx.engine) == null ? void 0 : _a.props) == null ? void 0 : _b.locale) || "zh-CN";
  const [shouldRenderContent, setShouldRenderContent] = (0, import_react.useState)(false);
  import_utils.locales.init(import_reservationConstants.PISELL_RESERVATION_PAGE_LOCALES, engineLocale);
  (0, import_react.useEffect)(() => {
    if (!open) {
      setShouldRenderContent(false);
      return void 0;
    }
    const timer = window.setTimeout(() => {
      setShouldRenderContent(true);
    }, CONTENT_RENDER_DELAY);
    return () => {
      window.clearTimeout(timer);
    };
  }, [open]);
  const handleSelectResource = (0, import_react.useCallback)(
    (payload) => {
      onClick == null ? void 0 : onClick(payload);
    },
    [onClick]
  );
  const resourceSelectMode = (0, import_react.useMemo)(
    () => ({
      enabled: true,
      onSelectResource: handleSelectResource
    }),
    [handleSelectResource]
  );
  const normalizedScheduleValue = (0, import_react.useMemo)(
    () => normalizeScheduleValue(scheduleValue),
    [scheduleValue]
  );
  return /* @__PURE__ */ import_react.default.createElement(
    import_compensatedPisellContainer.default,
    {
      renderType: "modal",
      props: {
        height: "99%",
        platform: "pc",
        open,
        onCancel: onClose,
        title: title ?? import_utils.locales.getText(I18N_TITLE),
        footer: null,
        destroyOnClose: true,
        width: DIALOG_WIDTH,
        className: "pisell-select-floor-map-resource-dialog-modal",
        bodyStyle: DIALOG_BODY_STYLE,
        wrapClassName: "pisell-select-floor-map-resource-dialog"
      }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-select-floor-map-resource-dialog-content" }, shouldRenderContent ? /* @__PURE__ */ import_react.default.createElement(
      import_PisellReservation.PisellReservationCore,
      {
        reservationBiz: reservationBiz ?? businessCode,
        associatedMenuListIds,
        scheduleValue: normalizedScheduleValue,
        floorPlanId,
        floorPlanCode,
        floorPlanCanvasWidth,
        floorPlanCanvasHeight,
        dataSources,
        floorMap,
        bodyViewSwitchable: false,
        lockedBodyView: "floorMap",
        resourceSelectMode
      }
    ) : /* @__PURE__ */ import_react.default.createElement(SelectFloorMapResourceSkeleton, null))
  );
}
var SelectFloorMapResourceDialog_default = SelectFloorMapResourceDialog;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SelectFloorMapResourceDialog
});
