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/components/pisellFloorMapLayout/components/FloorMapToolbar.tsx
var FloorMapToolbar_exports = {};
__export(FloorMapToolbar_exports, {
  FloorMapToolbar: () => FloorMapToolbar,
  default: () => FloorMapToolbar_default
});
module.exports = __toCommonJS(FloorMapToolbar_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_antd = require("antd");
var import_icons = require("@ant-design/icons");
var import_types = require("../types");
var import_floorMapElementKindUtils = require("../utils/floorMapElementKindUtils");
var import_floorMapBuiltinShapes = require("../utils/floorMapBuiltinShapes");
var import_floorMapDropUtils = require("../utils/floorMapDropUtils");
var import_utils = require("@pisell/utils");
var import_floorMapLayoutConstants = require("../floorMapLayoutConstants");
var import_floorMapToolbarPalette = require("../utils/floorMapToolbarPalette");
var import_FloorMapToolbarViewAllModal = require("./FloorMapToolbarViewAllModal");
var import_FloorMapToolbar = require("./FloorMapToolbar.less");
var I18N_TB = "pisell-floor-map-layout.toolbar";
function resolveBindingDataSourceKey(kind, dataSources) {
  var _a;
  const allKeys = Object.keys(dataSources ?? {});
  const allowed = ((_a = kind.allowedDataSourceKeys) == null ? void 0 : _a.length) ? kind.allowedDataSourceKeys.filter((x) => allKeys.includes(x)) : allKeys;
  return allowed[0];
}
var DEFAULT_PLACEMENT_SIZE = import_floorMapElementKindUtils.FLOOR_MAP_RESOURCE_PLACE_DEFAULT;
var DEFAULT_DECORATION_SIZE = 48;
function getToolbarPreviewScaledStyle(cellW, cellH, contentW, contentH) {
  const scale = Math.min(cellW / contentW, cellH / contentH);
  return {
    width: contentW,
    height: contentH,
    transform: `translate(-50%, -50%) scale(${scale})`,
    transformOrigin: "center center"
  };
}
function getUnplacedRecordsForKey(dataSourceKey, dataSources, elements) {
  const used = new Set(
    elements.filter((e) => {
      var _a;
      return ((_a = e.dataBinding) == null ? void 0 : _a.dataSourceKey) === dataSourceKey;
    }).map((e) => e.dataBinding.recordId)
  );
  const list = dataSources[dataSourceKey] ?? [];
  return list.filter(
    (r) => r && typeof r.id === "string" && !used.has(r.id)
  );
}
function buildScenePreviewMergedItem(kind, dataSourceKey, size, builtinShapeKey) {
  var _a;
  const el = {
    instanceId: `preview_${kind.value}`,
    canvasId: "",
    x: 0,
    y: 0,
    width: size.width,
    height: size.height,
    elementKind: kind.value,
    shape: kind.defaultShape,
    dataBinding: dataSourceKey && (0, import_floorMapElementKindUtils.resolveDataBindingPolicy)(kind) !== "none" ? { dataSourceKey, recordId: "" } : void 0,
    ...kind.value === import_types.FLOOR_MAP_IMAGE_ELEMENT_KIND ? { imageUrl: "" } : {},
    /** 内置图形 palette 预览：每张卡片对应一个具体 builtinShapeKey */
    ...kind.value === import_types.FLOOR_MAP_BUILTIN_SHAPE_ELEMENT_KIND ? {
      builtinShapeKey: builtinShapeKey ?? ((_a = import_floorMapBuiltinShapes.FLOOR_MAP_BUILTIN_SHAPES[0]) == null ? void 0 : _a.key)
    } : {}
  };
  return {
    id: el.instanceId,
    instanceId: el.instanceId,
    x: 0,
    y: 0,
    width: size.width,
    height: size.height,
    shape: kind.defaultShape,
    elementKind: kind.value,
    _sceneElement: el
  };
}
var STAGE_PREVIEW_SIZE = { width: 160, height: 64 };
var IMAGE_PREVIEW_SIZE = { width: 140, height: 80 };
var BUILTIN_SHAPE_PREVIEW_SIZE = { width: 96, height: 96 };
var PALETTE_PREVIEW_CELL_BASE = {
  stage: { w: 92, h: 40 },
  placement: { w: 80, h: 54 }
};
var SIDEBAR_PALETTE_PREVIEW_SCALE = 0.5;
var MODAL_PALETTE_PREVIEW_SCALE_RELATIVE_TO_SIDEBAR = 1;
function resolvePalettePreviewScale(modal) {
  return modal ? SIDEBAR_PALETTE_PREVIEW_SCALE * MODAL_PALETTE_PREVIEW_SCALE_RELATIVE_TO_SIDEBAR : SIDEBAR_PALETTE_PREVIEW_SCALE;
}
function scalePalettePreviewCell(n, modal) {
  return Math.max(8, Math.round(n * resolvePalettePreviewScale(modal)));
}
function getPalettePreviewCellSize(options) {
  const { isStage, placementLike, decorationPreviewSize, modal = false } = options;
  const baseW = isStage ? PALETTE_PREVIEW_CELL_BASE.stage.w : placementLike ? PALETTE_PREVIEW_CELL_BASE.placement.w : decorationPreviewSize;
  const baseH = isStage ? PALETTE_PREVIEW_CELL_BASE.stage.h : placementLike ? PALETTE_PREVIEW_CELL_BASE.placement.h : decorationPreviewSize;
  return {
    cellW: scalePalettePreviewCell(baseW, modal),
    cellH: scalePalettePreviewCell(baseH, modal)
  };
}
function FloorMapToolbar(props) {
  var _a;
  const {
    config,
    dataSources,
    dataSourceLabels = {},
    canCreate,
    placeMode,
    onPlaceModeChange,
    renderPreviewItem,
    placementPreviewSize = DEFAULT_PLACEMENT_SIZE,
    decorationPreviewSize = DEFAULT_DECORATION_SIZE,
    sceneElements = [],
    onSave,
    saving,
    saveError,
    layoutDirty,
    className,
    onPaletteCardPointerDown,
    consumeToolbarClickIfTouchDrag,
    phoneLayout = false,
    defaultCollapsed = false,
    onRequestPlaceAtCanvasCenter,
    paletteSidebarVisibleLimit,
    onBulkAddPaletteToCanvas,
    renderPaletteViewAllModal,
    onDirectPlacePaletteItem,
    onResourcePickerConfirmPlace,
    renderResourcePickerModal
  } = props;
  const [collapsed, setCollapsed] = (0, import_react.useState)(() => defaultCollapsed === true);
  const [viewAllModal, setViewAllModal] = (0, import_react.useState)(null);
  const [resourcePickerOpen, setResourcePickerOpen] = (0, import_react.useState)(false);
  const [resourcePickerCtx, setResourcePickerCtx] = (0, import_react.useState)(null);
  const handleToggleCollapsed = (0, import_react.useCallback)(() => {
    setCollapsed((prev) => !prev);
  }, []);
  const paletteKinds = (0, import_react.useMemo)(
    () => (config.elementKinds ?? []).filter((k) => k.showInPalette !== false),
    [config.elementKinds]
  );
  const categories = (0, import_react.useMemo)(() => {
    const raw = config.elementKindCategories ?? [];
    const sorted = [...raw].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
    return sorted.length ? sorted : [
      {
        id: "_uncat",
        label: import_utils.locales.getText(`${I18N_TB}.category-fallback`),
        order: 0
      }
    ];
  }, [config.elementKindCategories]);
  const kindsByCategory = (0, import_react.useMemo)(() => {
    var _a2;
    const map = /* @__PURE__ */ new Map();
    for (const c of categories) {
      map.set(c.id, []);
    }
    const fallbackId = ((_a2 = categories[0]) == null ? void 0 : _a2.id) ?? "_uncat";
    for (const k of paletteKinds) {
      const cid = k.categoryId ?? fallbackId;
      if (!map.has(cid)) map.set(cid, []);
      map.get(cid).push(k);
    }
    return map;
  }, [categories, paletteKinds]);
  const paletteEntriesByCategory = (0, import_react.useMemo)(() => {
    const map = /* @__PURE__ */ new Map();
    for (const c of categories) {
      const kinds = kindsByCategory.get(c.id) ?? [];
      map.set(
        c.id,
        (0, import_floorMapToolbarPalette.buildToolbarPaletteEntries)(
          kinds,
          (shapeDef) => import_utils.locales.getText(shapeDef.labelKey)
        )
      );
    }
    return map;
  }, [categories, kindsByCategory]);
  const collapseToolbarOnPhone = (0, import_react.useCallback)(() => {
    if (phoneLayout) setCollapsed(true);
  }, [phoneLayout]);
  const directPlacePaletteItem = (item) => {
    onDirectPlacePaletteItem == null ? void 0 : onDirectPlacePaletteItem(item);
    onPlaceModeChange(null);
    collapseToolbarOnPhone();
  };
  const cancelPlaceMode = () => {
    onPlaceModeChange(null);
    setResourcePickerOpen(false);
    setResourcePickerCtx(null);
  };
  const openResourcePickerForBindingKind = (0, import_react.useCallback)(
    (kind, carryMode) => {
      const key = resolveBindingDataSourceKey(kind, dataSources);
      if (!key) {
        import_antd.message.warning(import_utils.locales.getText(`${I18N_TB}.no-data-sources`));
        setResourcePickerOpen(false);
        setResourcePickerCtx(null);
        return;
      }
      const unplaced = getUnplacedRecordsForKey(
        key,
        dataSources,
        sceneElements
      );
      const sameKind = (carryMode == null ? void 0 : carryMode.elementKind) === kind.value ? carryMode : void 0;
      const mode = {
        type: "scene",
        elementKind: kind.value,
        dataSourceKey: key,
        recordId: sameKind == null ? void 0 : sameKind.recordId,
        recordIds: sameKind == null ? void 0 : sameKind.recordIds
      };
      onPlaceModeChange(mode);
      setResourcePickerCtx({ mode, dataSourceKey: key, records: unplaced });
      setResourcePickerOpen(true);
      collapseToolbarOnPhone();
    },
    [dataSources, sceneElements, onPlaceModeChange, collapseToolbarOnPhone]
  );
  const handleSelectKind = (kind) => {
    if ((0, import_floorMapElementKindUtils.isDirectPlacePaletteKind)(kind)) {
      setResourcePickerOpen(false);
      setResourcePickerCtx(null);
      directPlacePaletteItem({ elementKind: kind.value });
      return;
    }
    const isSame = (placeMode == null ? void 0 : placeMode.type) === "scene" && placeMode.elementKind === kind.value;
    if (isSame) {
      cancelPlaceMode();
      return;
    }
    const carry = (placeMode == null ? void 0 : placeMode.type) === "scene" ? placeMode : void 0;
    openResourcePickerForBindingKind(kind, carry);
  };
  const handleSelectBuiltinShape = (kind, shapeKey) => {
    directPlacePaletteItem({
      elementKind: kind.value,
      builtinShapeKey: shapeKey
    });
  };
  const resourcePickerModalProps = resourcePickerOpen && resourcePickerCtx ? {
    open: true,
    records: resourcePickerCtx.records,
    mode: "multiple",
    value: ((_a = resourcePickerCtx.mode.recordIds) == null ? void 0 : _a.length) ? resourcePickerCtx.mode.recordIds : resourcePickerCtx.mode.recordId ? [resourcePickerCtx.mode.recordId] : [],
    title: dataSourceLabels[resourcePickerCtx.dataSourceKey] ? import_utils.locales.getText(`${I18N_TB}.select-with-label`).replace(
      "{label}",
      dataSourceLabels[resourcePickerCtx.dataSourceKey]
    ) : import_utils.locales.getText(`${I18N_TB}.open-resource-picker`),
    onClose: cancelPlaceMode,
    onConfirm: (ids) => {
      const list = (ids == null ? void 0 : ids.filter(Boolean)) ?? [];
      if (list.length === 0) {
        import_antd.message.warning(
          import_utils.locales.getText(`${I18N_TB}.resource-picker-none-selected`)
        );
        return;
      }
      const scene = {
        ...resourcePickerCtx.mode,
        recordIds: list,
        recordId: void 0
      };
      setResourcePickerOpen(false);
      setResourcePickerCtx(null);
      const placed = (onResourcePickerConfirmPlace == null ? void 0 : onResourcePickerConfirmPlace(scene)) ?? false;
      if (!placed) {
        onPlaceModeChange(scene);
      }
    }
  } : null;
  const resourcePickerModal = resourcePickerModalProps && renderResourcePickerModal ? renderResourcePickerModal(resourcePickerModalProps) : null;
  const warnedMissingResourcePickerRef = (0, import_react.useRef)(false);
  (0, import_react.useEffect)(() => {
    if (!resourcePickerModalProps || renderResourcePickerModal) {
      return;
    }
    if (warnedMissingResourcePickerRef.current) {
      return;
    }
    warnedMissingResourcePickerRef.current = true;
    if (typeof console !== "undefined") {
      console.warn(
        "[PisellFloorMapLayout] renderResourcePickerModal 未注入，资源选择弹窗不会渲染。"
      );
    }
  }, [resourcePickerModalProps, renderResourcePickerModal]);
  const renderPaletteEntryPreview = (entry) => {
    const k = entry.kind;
    const policy = (0, import_floorMapElementKindUtils.resolveDataBindingPolicy)(k);
    const isStage = k.value === import_types.FLOOR_MAP_STAGE_ELEMENT_KIND;
    const isImageKind = k.value === import_types.FLOOR_MAP_IMAGE_ELEMENT_KIND;
    const isBuiltinShapeKind = k.value === import_types.FLOOR_MAP_BUILTIN_SHAPE_ELEMENT_KIND;
    const placementLike = policy !== "none" && !isStage || isImageKind || isBuiltinShapeKind;
    const size = entry.shapeDef ? entry.shapeDef.defaultSize : isStage ? STAGE_PREVIEW_SIZE : placementLike ? isImageKind ? IMAGE_PREVIEW_SIZE : isBuiltinShapeKind ? BUILTIN_SHAPE_PREVIEW_SIZE : placementPreviewSize : {
      width: decorationPreviewSize,
      height: decorationPreviewSize
    };
    const item = buildScenePreviewMergedItem(
      k,
      void 0,
      { width: size.width, height: size.height },
      entry.builtinShapeKey
    );
    const { cellW, cellH } = getPalettePreviewCellSize({
      isStage,
      placementLike,
      decorationPreviewSize,
      /** renderPaletteEntryPreview 当前只用于 View All modal，固定走 modal 放大尺寸 */
      modal: true
    });
    const previewW = entry.shapeDef ? entry.shapeDef.defaultSize.width : isImageKind ? IMAGE_PREVIEW_SIZE.width : isBuiltinShapeKind ? BUILTIN_SHAPE_PREVIEW_SIZE.width : placementPreviewSize.width;
    const previewH = entry.shapeDef ? entry.shapeDef.defaultSize.height : isImageKind ? IMAGE_PREVIEW_SIZE.height : isBuiltinShapeKind ? BUILTIN_SHAPE_PREVIEW_SIZE.height : placementPreviewSize.height;
    const stageW = item.width ?? cellW;
    const stageH = item.height ?? cellH;
    const contentW = entry.shapeDef ? entry.shapeDef.defaultSize.width : isStage ? stageW : placementLike ? previewW : decorationPreviewSize;
    const contentH = entry.shapeDef ? entry.shapeDef.defaultSize.height : isStage ? stageH : placementLike ? previewH : decorationPreviewSize;
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-cell`,
        style: { width: cellW, height: cellH }
      },
      renderPreviewItem ? /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-content`,
          style: getToolbarPreviewScaledStyle(
            cellW,
            cellH,
            contentW,
            contentH
          )
        },
        renderPreviewItem(item)
      ) : /* @__PURE__ */ import_react.default.createElement("span", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-fallback` }, entry.label)
    );
  };
  const viewAllModalPlatform = phoneLayout ? "h5" : "pc";
  const paletteViewAllModal = viewAllModal ? renderPaletteViewAllModal ? renderPaletteViewAllModal({
    open: true,
    categoryLabel: viewAllModal.categoryLabel,
    entries: viewAllModal.entries,
    onClose: () => setViewAllModal(null),
    onConfirm: (items) => {
      onBulkAddPaletteToCanvas == null ? void 0 : onBulkAddPaletteToCanvas(items);
      collapseToolbarOnPhone();
    },
    renderEntryPreview: (entry) => renderPaletteEntryPreview(entry),
    platform: viewAllModalPlatform
  }) : /* @__PURE__ */ import_react.default.createElement(
    import_FloorMapToolbarViewAllModal.FloorMapToolbarViewAllModal,
    {
      open: true,
      categoryLabel: viewAllModal.categoryLabel,
      entries: viewAllModal.entries,
      onClose: () => setViewAllModal(null),
      onConfirm: (items) => {
        onBulkAddPaletteToCanvas == null ? void 0 : onBulkAddPaletteToCanvas(items);
        collapseToolbarOnPhone();
      },
      renderEntryPreview: (entry) => renderPaletteEntryPreview(entry),
      platform: viewAllModalPlatform
    }
  ) : null;
  const renderBuiltinShapePaletteCard = (kind, shapeDef) => {
    const shapeLabel = import_utils.locales.getText(shapeDef.labelKey);
    const previewW = shapeDef.defaultSize.width;
    const previewH = shapeDef.defaultSize.height;
    const { cellW, cellH } = getPalettePreviewCellSize({
      isStage: false,
      placementLike: true,
      decorationPreviewSize
    });
    const item = buildScenePreviewMergedItem(
      kind,
      void 0,
      { width: previewW, height: previewH },
      shapeDef.key
    );
    const paletteDragPayload = {
      elementKind: kind.value,
      builtinShapeKey: shapeDef.key
    };
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        key: `${kind.value}-${shapeDef.key}`,
        className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-card-wrap`
      },
      /* @__PURE__ */ import_react.default.createElement(
        "button",
        {
          type: "button",
          draggable: true,
          className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-card`,
          onClick: () => {
            if (consumeToolbarClickIfTouchDrag == null ? void 0 : consumeToolbarClickIfTouchDrag()) return;
            handleSelectBuiltinShape(kind, shapeDef.key);
          },
          onPointerDown: (e) => onPaletteCardPointerDown == null ? void 0 : onPaletteCardPointerDown(paletteDragPayload, e),
          onDragStart: (e) => {
            e.dataTransfer.setData(
              import_floorMapDropUtils.FLOOR_MAP_PALETTE_DRAG_MIME,
              JSON.stringify(paletteDragPayload)
            );
            e.dataTransfer.effectAllowed = "copy";
          },
          title: import_utils.locales.getText(`${I18N_TB}.palette-card-title`).replace(/\{name\}/g, shapeLabel)
        },
        /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-cell`,
            style: { width: cellW, height: cellH }
          },
          renderPreviewItem ? /* @__PURE__ */ import_react.default.createElement(
            "div",
            {
              className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-content`,
              style: getToolbarPreviewScaledStyle(
                cellW,
                cellH,
                previewW,
                previewH
              )
            },
            renderPreviewItem(item)
          ) : /* @__PURE__ */ import_react.default.createElement("span", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-fallback` }, shapeLabel)
        ),
        /* @__PURE__ */ import_react.default.createElement("span", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-card-label` }, shapeLabel)
      )
    );
  };
  const renderKindCard = (k) => {
    var _a2, _b, _c, _d;
    const policy = (0, import_floorMapElementKindUtils.resolveDataBindingPolicy)(k);
    const isStage = k.value === import_types.FLOOR_MAP_STAGE_ELEMENT_KIND;
    const isImageKind = k.value === import_types.FLOOR_MAP_IMAGE_ELEMENT_KIND;
    const isBuiltinShapeKind = k.value === import_types.FLOOR_MAP_BUILTIN_SHAPE_ELEMENT_KIND;
    const placementLike = policy !== "none" && !isStage || isImageKind || isBuiltinShapeKind;
    const size = isStage ? STAGE_PREVIEW_SIZE : placementLike ? isImageKind ? IMAGE_PREVIEW_SIZE : isBuiltinShapeKind ? BUILTIN_SHAPE_PREVIEW_SIZE : placementPreviewSize : {
      width: decorationPreviewSize,
      height: decorationPreviewSize
    };
    const activeDs = (placeMode == null ? void 0 : placeMode.type) === "scene" && placeMode.elementKind === k.value ? placeMode.dataSourceKey : void 0;
    const activeBuiltinShapeKey = isBuiltinShapeKind ? (placeMode == null ? void 0 : placeMode.type) === "scene" && placeMode.elementKind === k.value ? placeMode.builtinShapeKey ?? ((_a2 = import_floorMapBuiltinShapes.FLOOR_MAP_BUILTIN_SHAPES[0]) == null ? void 0 : _a2.key) : (_b = import_floorMapBuiltinShapes.FLOOR_MAP_BUILTIN_SHAPES[0]) == null ? void 0 : _b.key : void 0;
    const item = buildScenePreviewMergedItem(
      k,
      activeDs,
      size,
      activeBuiltinShapeKey
    );
    const isActive = (placeMode == null ? void 0 : placeMode.type) === "scene" && placeMode.elementKind === k.value;
    const { cellW, cellH } = getPalettePreviewCellSize({
      isStage,
      placementLike,
      decorationPreviewSize
    });
    const previewW = isImageKind ? IMAGE_PREVIEW_SIZE.width : isBuiltinShapeKind ? BUILTIN_SHAPE_PREVIEW_SIZE.width : placementPreviewSize.width;
    const previewH = isImageKind ? IMAGE_PREVIEW_SIZE.height : isBuiltinShapeKind ? BUILTIN_SHAPE_PREVIEW_SIZE.height : placementPreviewSize.height;
    const stageW = item.width ?? cellW;
    const stageH = item.height ?? cellH;
    const allKeys = Object.keys(dataSources);
    const allowedKeys = ((_c = k.allowedDataSourceKeys) == null ? void 0 : _c.length) ? k.allowedDataSourceKeys.filter((x) => allKeys.includes(x)) : allKeys;
    const paletteDragPayload = {
      elementKind: k.value,
      ...(placeMode == null ? void 0 : placeMode.type) === "scene" && placeMode.elementKind === k.value ? {
        dataSourceKey: placeMode.dataSourceKey,
        ...placeMode.recordIds && placeMode.recordIds.length > 0 ? { recordIds: placeMode.recordIds } : placeMode.recordId ? { recordId: placeMode.recordId } : {}
      } : {},
      /**
       * 内置图形 kind：把侧栏 Select 选定的 `builtinShapeKey` 写入拖拽 payload，
       * 让 drop / 触摸落点能感知用户预选的图形（与资源 kind 透传 recordIds 同款）。
       * 即使未激活该 kind，也回退枚举首项，避免拖到画布时落出空白占位。
       */
      ...isBuiltinShapeKind ? {
        builtinShapeKey: activeBuiltinShapeKey ?? ((_d = import_floorMapBuiltinShapes.FLOOR_MAP_BUILTIN_SHAPES[0]) == null ? void 0 : _d.key)
      } : {}
    };
    return /* @__PURE__ */ import_react.default.createElement("div", { key: k.value, className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-card-wrap` }, /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        type: "button",
        draggable: true,
        className: (0, import_classnames.default)(
          `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-card`,
          !placementLike ? `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-card-deco` : void 0,
          { [`${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-card-active`]: isActive }
        ),
        onClick: () => {
          if (consumeToolbarClickIfTouchDrag == null ? void 0 : consumeToolbarClickIfTouchDrag()) return;
          handleSelectKind(k);
        },
        onPointerDown: (e) => onPaletteCardPointerDown == null ? void 0 : onPaletteCardPointerDown(paletteDragPayload, e),
        onDragStart: (e) => {
          e.dataTransfer.setData(
            import_floorMapDropUtils.FLOOR_MAP_PALETTE_DRAG_MIME,
            JSON.stringify(paletteDragPayload)
          );
          e.dataTransfer.effectAllowed = "copy";
        },
        title: import_utils.locales.getText(`${I18N_TB}.palette-card-title`).replace(/\{name\}/g, k.label)
      },
      /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-cell`,
          style: { width: cellW, height: cellH }
        },
        renderPreviewItem ? /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-content`,
            style: getToolbarPreviewScaledStyle(
              cellW,
              cellH,
              isStage ? stageW : placementLike ? previewW : decorationPreviewSize,
              isStage ? stageH : placementLike ? previewH : decorationPreviewSize
            )
          },
          renderPreviewItem(item)
        ) : /* @__PURE__ */ import_react.default.createElement("span", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-fallback` }, k.label)
      ),
      /* @__PURE__ */ import_react.default.createElement("span", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-card-label` }, k.label)
    ));
  };
  const collapseBtn = /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: (0, import_classnames.default)(
        `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-collapse-handle`,
        phoneLayout && `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-collapse-handle--in-drawer`
      ),
      onClick: handleToggleCollapsed,
      "aria-label": collapsed ? import_utils.locales.getText(`${I18N_TB}.expand`) : import_utils.locales.getText(`${I18N_TB}.collapse`),
      title: collapsed ? import_utils.locales.getText(`${I18N_TB}.expand`) : import_utils.locales.getText(`${I18N_TB}.collapse`)
    },
    collapsed ? /* @__PURE__ */ import_react.default.createElement(import_icons.RightOutlined, null) : /* @__PURE__ */ import_react.default.createElement(import_icons.LeftOutlined, null)
  );
  const toolbarInner = /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-inner` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-body` }, canCreate && /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, categories.map((cat) => {
    const entries = paletteEntriesByCategory.get(cat.id) ?? [];
    if (!entries.length) return null;
    const visibleEntries = (0, import_floorMapToolbarPalette.getPaletteSidebarVisibleEntries)(
      entries,
      paletteSidebarVisibleLimit
    );
    const showViewAll = (0, import_floorMapToolbarPalette.shouldShowPaletteViewAll)(
      entries.length,
      paletteSidebarVisibleLimit
    );
    return /* @__PURE__ */ import_react.default.createElement(
      "section",
      {
        key: cat.id,
        className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-section`
      },
      /* @__PURE__ */ import_react.default.createElement("h3", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-section-title` }, cat.label),
      /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-list` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-preview-group` }, visibleEntries.map(
        (entry) => entry.builtinShapeKey && entry.shapeDef ? renderBuiltinShapePaletteCard(
          entry.kind,
          entry.shapeDef
        ) : renderKindCard(entry.kind)
      ), showViewAll ? /* @__PURE__ */ import_react.default.createElement(
        "button",
        {
          type: "button",
          className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all`,
          onClick: () => {
            setViewAllModal({
              categoryLabel: cat.label,
              entries
            });
            collapseToolbarOnPhone();
          }
        },
        import_utils.locales.getText(`${I18N_TB}.view-all`)
      ) : null))
    );
  })), phoneLayout && onRequestPlaceAtCanvasCenter && (placeMode == null ? void 0 : placeMode.type) === "scene" ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-section` }, /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: (0, import_classnames.default)(`${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-btn`, "primary"),
      onClick: () => {
        onRequestPlaceAtCanvasCenter();
        collapseToolbarOnPhone();
      }
    },
    import_utils.locales.getText(`${I18N_TB}.add-to-canvas`)
  )) : null), onSave && config.canvasUi.canEdit && /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-footer` }, layoutDirty ? /* @__PURE__ */ import_react.default.createElement("span", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-dirty-hint`, role: "status" }, import_utils.locales.getText(`${I18N_TB}.layout-dirty-hint`)) : null, saveError && /* @__PURE__ */ import_react.default.createElement("span", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-error` }, typeof saveError === "string" ? saveError : saveError == null ? void 0 : saveError.message), /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: (0, import_classnames.default)(`${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-btn`, "primary", {
        [`${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-save-dirty`]: layoutDirty
      }),
      disabled: saving,
      onClick: onSave
    },
    saving ? import_utils.locales.getText(`${I18N_TB}.saving`) : import_utils.locales.getText(`${I18N_TB}.save`)
  )));
  if (phoneLayout) {
    return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)(`${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar`, className) }, paletteViewAllModal, resourcePickerModal, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Drawer,
      {
        placement: "left",
        open: !collapsed,
        onClose: () => setCollapsed(true),
        width: "min(320px, 88vw)",
        zIndex: import_floorMapLayoutConstants.FLOOR_MAP_PHONE_TOOLBAR_DRAWER_Z_INDEX,
        maskClosable: true,
        destroyOnClose: false,
        closable: false,
        forceRender: false,
        rootClassName: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-phone-drawer-root`,
        classNames: {
          body: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-phone-drawer-body`
        },
        styles: {
          body: {
            padding: 0,
            /** 由 Less 设为 visible，便于折叠柄伸出面板；列表滚动在 toolbar-inner / body */
            overflow: "visible",
            display: "flex",
            flexDirection: "column",
            height: "100%"
          }
        },
        getContainer: typeof document !== "undefined" ? () => document.body : void 0
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-phone-drawer-inner` }, toolbarInner, collapseBtn)
    ), collapsed ? /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        type: "button",
        className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-phone-peek-trigger`,
        onClick: () => setCollapsed(false),
        "aria-label": import_utils.locales.getText(`${I18N_TB}.expand`),
        title: import_utils.locales.getText(`${I18N_TB}.expand`)
      },
      /* @__PURE__ */ import_react.default.createElement(import_icons.RightOutlined, null)
    ) : null);
  }
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)(
        `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar`,
        `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-sidebar`,
        collapsed && `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-sidebar--collapsed`,
        className
      )
    },
    paletteViewAllModal,
    resourcePickerModal,
    collapseBtn,
    toolbarInner
  );
}
var FloorMapToolbar_default = FloorMapToolbar;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FloorMapToolbar
});
