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/FloorMapEditPanel.tsx
var FloorMapEditPanel_exports = {};
__export(FloorMapEditPanel_exports, {
  FloorMapEditPanel: () => FloorMapEditPanel,
  default: () => FloorMapEditPanel_default
});
module.exports = __toCommonJS(FloorMapEditPanel_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_classnames = __toESM(require("classnames"));
var import_icons = require("@ant-design/icons");
var import_antd = require("antd");
var import_types = require("../types");
var import_floorMapElementKindUtils = require("../utils/floorMapElementKindUtils");
var import_floorMapBuiltinShapes = require("../utils/floorMapBuiltinShapes");
var import_floorMapElementNameAsTitle = require("../utils/floorMapElementNameAsTitle");
var import_FloorMapDataForm = require("./FloorMapDataForm");
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var import_floorMapCanvasDisplay = require("../utils/floorMapCanvasDisplay");
var import_floorMapLayoutConstants = require("../floorMapLayoutConstants");
var import_floorMapDataRecordLabel = require("../utils/floorMapDataRecordLabel");
var import_FloorMapEditPanel = require("./FloorMapEditPanel.less");
var PREFIX = "pisell-floor-map-layout";
var I18N_EP = "pisell-floor-map-layout.edit-panel";
function resolveDataSourceRecordForm(content, ctx) {
  if (typeof content === "function") {
    return content(
      ctx
    );
  }
  return content;
}
function FloorMapEditPanel(props) {
  var _a, _b, _c, _d;
  const {
    sceneElement,
    itemId,
    onUpdate,
    onSaveRecord,
    onClose,
    onDelete,
    recordFormColumns,
    dataSourceRecordForm,
    config,
    dataSources,
    savingRecord,
    dataSourceLabels = {},
    layoutDraftDirty,
    showDataSourceRecordFormBlock: showRecordFormProp,
    className
  } = props;
  const [form] = import_antd.Form.useForm();
  const skipFormValuesChangeRef = (0, import_react.useRef)(false);
  const [formHasUnappliedChanges, setFormHasUnappliedChanges] = (0, import_react.useState)(false);
  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";
  (0, import_floorMapCanvasDisplay.initFloorMapLayoutLocales)(engineLocale);
  const ep = (0, import_react.useMemo)(
    () => ({
      elementProps: import_utils.locales.getText(`${I18N_EP}.element-props`),
      closeAria: import_utils.locales.getText(`${I18N_EP}.close-aria`),
      hintApply: import_utils.locales.getText(`${I18N_EP}.hint-apply`),
      hintSave: import_utils.locales.getText(`${I18N_EP}.hint-save`),
      sectionLayout: import_utils.locales.getText(`${I18N_EP}.section-layout`),
      lockOn: import_utils.locales.getText(`${I18N_EP}.lock-on`),
      lockOff: import_utils.locales.getText(`${I18N_EP}.lock-off`),
      labelX: import_utils.locales.getText(`${I18N_EP}.label-x`),
      labelY: import_utils.locales.getText(`${I18N_EP}.label-y`),
      labelZ: import_utils.locales.getText(`${I18N_EP}.label-z`),
      labelWidth: import_utils.locales.getText(`${I18N_EP}.label-width`),
      labelHeight: import_utils.locales.getText(`${I18N_EP}.label-height`),
      labelName: import_utils.locales.getText(`${I18N_EP}.label-name`),
      labelNameStage: import_utils.locales.getText(`${I18N_EP}.label-name-stage`),
      phNameStage: import_utils.locales.getText(`${I18N_EP}.ph-name-stage`),
      phName: import_utils.locales.getText(`${I18N_EP}.ph-name`),
      labelNameAsTitle: import_utils.locales.getText(`${I18N_EP}.label-name-as-title`),
      tipNameAsTitle: import_utils.locales.getText(`${I18N_EP}.tip-name-as-title`),
      labelImageUrl: import_utils.locales.getText(`${I18N_EP}.label-image-url`),
      extraImageUrl: import_utils.locales.getText(`${I18N_EP}.extra-image-url`),
      phHttps: import_utils.locales.getText(`${I18N_EP}.ph-https`),
      labelBuiltinShape: import_utils.locales.getText(`${I18N_EP}.label-builtin-shape`),
      extraBuiltinShape: import_utils.locales.getText(`${I18N_EP}.extra-builtin-shape`),
      phBuiltinShape: import_utils.locales.getText(`${I18N_EP}.ph-builtin-shape`),
      labelCanvas: import_utils.locales.getText(`${I18N_EP}.label-canvas`),
      apply: import_utils.locales.getText(`${I18N_EP}.apply`),
      dataBinding: import_utils.locales.getText(`${I18N_EP}.data-binding`),
      dataBindingNote: import_utils.locales.getText(`${I18N_EP}.data-binding-note`),
      labelDataSource: import_utils.locales.getText(`${I18N_EP}.label-data-source`),
      phDataSource: import_utils.locales.getText(`${I18N_EP}.ph-data-source`),
      labelPickRow: import_utils.locales.getText(`${I18N_EP}.label-pick-row`),
      phPickRow: import_utils.locales.getText(`${I18N_EP}.ph-pick-row`),
      phNoRows: import_utils.locales.getText(`${I18N_EP}.ph-no-rows`),
      hintUnbound: import_utils.locales.getText(`${I18N_EP}.hint-unbound`),
      recordTitle: import_utils.locales.getText(`${I18N_EP}.record-title`),
      popTitle: import_utils.locales.getText(`${I18N_EP}.pop-title`),
      popDesc: import_utils.locales.getText(`${I18N_EP}.pop-desc`),
      btnDelete: import_utils.locales.getText(`${I18N_EP}.btn-delete`),
      btnCancel: import_utils.locales.getText(`${I18N_EP}.btn-cancel`),
      btnOkDelete: import_utils.locales.getText(`${I18N_EP}.btn-ok-delete`),
      labelElementKind: import_utils.locales.getText(`${I18N_EP}.label-element-kind`),
      hintKindBindingCleared: import_utils.locales.getText(
        `${I18N_EP}.hint-kind-binding-cleared`
      )
    }),
    [engineLocale]
  );
  const swappableKinds = (0, import_react.useMemo)(
    () => (0, import_floorMapElementKindUtils.getSwappableElementKindsInSameCategory)(config, sceneElement.elementKind),
    [config, sceneElement.elementKind]
  );
  const handleElementKindChange = (0, import_react.useCallback)(
    (nextKind) => {
      if (nextKind === sceneElement.elementKind) return;
      const hadBinding = Boolean(sceneElement.dataBinding);
      const patch = (0, import_floorMapElementKindUtils.patchSceneElementForKindSwitch)(
        config,
        sceneElement,
        nextKind
      );
      if (hadBinding && patch.dataBinding === void 0) {
        import_antd.message.info(ep.hintKindBindingCleared);
      }
      onUpdate(patch);
    },
    [config, sceneElement, onUpdate, ep.hintKindBindingCleared]
  );
  const canvasOptions = config.canvases.filter((c) => c.enabled).sort((a, b) => a.order - b.order);
  const kindConfig = (0, import_floorMapElementKindUtils.getElementKindConfig)(config, sceneElement.elementKind);
  const bindingPolicy = (0, import_floorMapElementKindUtils.resolveDataBindingPolicy)(kindConfig);
  const kindAllowsNameAsTitle = Boolean(kindConfig == null ? void 0 : kindConfig.nameAsTitleConfigurable);
  const allKeys = Object.keys(dataSources);
  const allowedKeys = ((_c = kindConfig == null ? void 0 : kindConfig.allowedDataSourceKeys) == null ? void 0 : _c.length) ? kindConfig.allowedDataSourceKeys.filter((k) => allKeys.includes(k)) : allKeys;
  const isImageKind = (0, import_floorMapElementKindUtils.isFloorMapImageElementKind)(sceneElement.elementKind);
  const isBuiltinShapeKind = (0, import_floorMapElementKindUtils.isFloorMapBuiltinShapeElementKind)(
    sceneElement.elementKind
  );
  const layoutLocked = Boolean(sceneElement.layoutTransformLocked);
  const initialValues = import_react.default.useMemo(() => {
    const builtinDef = isBuiltinShapeKind ? (0, import_floorMapBuiltinShapes.getFloorMapBuiltinShapeDef)(sceneElement.builtinShapeKey) : void 0;
    const bindingPolicy2 = (0, import_floorMapElementKindUtils.resolveDataBindingPolicy)(kindConfig);
    const dw = isImageKind ? 400 : isBuiltinShapeKind ? (builtinDef == null ? void 0 : builtinDef.defaultSize.width) ?? 96 : bindingPolicy2 !== "none" ? import_floorMapElementKindUtils.FLOOR_MAP_RESOURCE_PLACE_DEFAULT.width : 48;
    const dh = isImageKind ? 240 : isBuiltinShapeKind ? (builtinDef == null ? void 0 : builtinDef.defaultSize.height) ?? 96 : bindingPolicy2 !== "none" ? import_floorMapElementKindUtils.FLOOR_MAP_RESOURCE_PLACE_DEFAULT.height : 48;
    return {
      x: sceneElement.x,
      y: sceneElement.y,
      name: sceneElement.name ?? "",
      zIndex: sceneElement.zIndex ?? 0,
      width: sceneElement.width ?? dw,
      height: sceneElement.height ?? dh,
      canvasId: sceneElement.canvasId,
      imageUrl: sceneElement.imageUrl ?? "",
      builtinShapeKey: sceneElement.builtinShapeKey ?? void 0,
      /**
       * 编辑面板「将图元名作为资源标题」勾选项；持久化在 extensions[NAME_AS_TITLE_EXT_KEY]，
       * UI 仅在 kindConfig.nameAsTitleConfigurable 时渲染。
       */
      nameAsTitle: (0, import_floorMapElementNameAsTitle.isElementNameAsTitleEnabled)(sceneElement)
    };
  }, [sceneElement, isImageKind, isBuiltinShapeKind]);
  import_react.default.useEffect(() => {
    setFormHasUnappliedChanges(false);
  }, [itemId]);
  import_react.default.useEffect(() => {
    skipFormValuesChangeRef.current = true;
    form.setFieldsValue(initialValues);
    queueMicrotask(() => {
      skipFormValuesChangeRef.current = false;
      setFormHasUnappliedChanges(false);
    });
  }, [itemId, initialValues, form]);
  const handleFinish = (0, import_react.useCallback)(
    (values) => {
      const name = values.name != null ? String(values.name).trim() || void 0 : void 0;
      const patch = {
        name,
        canvasId: String(values.canvasId)
      };
      if (isImageKind) {
        const url = String(values.imageUrl ?? "").trim();
        patch.imageUrl = url || void 0;
      }
      if (isBuiltinShapeKind) {
        const raw = values.builtinShapeKey;
        const key = raw != null ? String(raw).trim() : "";
        patch.builtinShapeKey = key || void 0;
      }
      if (!layoutLocked) {
        patch.x = Number(values.x);
        patch.y = Number(values.y);
        patch.zIndex = values.zIndex != null ? Number(values.zIndex) : void 0;
        const w = Number(values.width);
        const h = Number(values.height);
        patch.width = Number.isFinite(w) ? Math.max(20, w) : void 0;
        patch.height = Number.isFinite(h) ? Math.max(20, h) : void 0;
      }
      if (kindAllowsNameAsTitle) {
        const enabled = Boolean(values.nameAsTitle) && Boolean(name);
        patch.extensions = (0, import_floorMapElementNameAsTitle.buildNameAsTitleExtensionsPatch)(
          sceneElement.extensions,
          enabled
        );
      }
      onUpdate(patch);
      setFormHasUnappliedChanges(false);
    },
    [
      onUpdate,
      isImageKind,
      isBuiltinShapeKind,
      layoutLocked,
      kindAllowsNameAsTitle,
      sceneElement.extensions
    ]
  );
  const binding = sceneElement.dataBinding;
  const record = binding ? ((_d = dataSources[binding.dataSourceKey]) == null ? void 0 : _d.find(
    (r) => r.id === binding.recordId
  )) ?? {} : {};
  const dataRecordBindOptions = (0, import_react.useMemo)(() => {
    if (bindingPolicy === "none") return [];
    const key = (binding == null ? void 0 : binding.dataSourceKey) ?? allowedKeys[0];
    if (!key) return [];
    const list = dataSources[key] ?? [];
    if (!list.length) return [];
    const usedByOther = new Set(
      (config.sceneElements ?? []).filter(
        (e) => {
          var _a2;
          return e.instanceId !== sceneElement.instanceId && ((_a2 = e.dataBinding) == null ? void 0 : _a2.dataSourceKey) === key;
        }
      ).map((e) => e.dataBinding.recordId)
    );
    return list.filter((r) => !usedByOther.has(r.id) || r.id === (binding == null ? void 0 : binding.recordId)).map((r) => ({
      value: r.id,
      label: (0, import_floorMapDataRecordLabel.formatDataRecordOptionLabel)(r)
    }));
  }, [
    bindingPolicy,
    binding,
    allowedKeys,
    dataSources,
    config.sceneElements,
    sceneElement.instanceId
  ]);
  const hasBoundDataRecord = Boolean(
    binding && (dataSources[binding.dataSourceKey] ?? []).some(
      (r) => r.id === binding.recordId
    )
  );
  const recordFormSlotRaw = binding ? dataSourceRecordForm == null ? void 0 : dataSourceRecordForm[binding.dataSourceKey] : void 0;
  const hasCustomRecordForm = recordFormSlotRaw !== void 0 && recordFormSlotRaw !== null && recordFormSlotRaw !== false;
  const showDataBindingSection = bindingPolicy !== "none";
  const showDataSourceRecordBlock = hasBoundDataRecord && Boolean(binding) && (onSaveRecord != null || hasCustomRecordForm);
  const showDataRecordEditorSection = showRecordFormProp !== false && showDataSourceRecordBlock && Boolean(binding);
  const recordFormContext = (0, import_react.useMemo)(() => {
    if (!binding) return null;
    return {
      dataSourceKey: binding.dataSourceKey,
      recordId: binding.recordId,
      record,
      dataSources,
      sceneElement,
      config,
      savingRecord: savingRecord ?? false,
      onSaveRecord: onSaveRecord ? (newData) => onSaveRecord(binding.dataSourceKey, binding.recordId, newData) : void 0
    };
  }, [
    binding,
    record,
    dataSources,
    sceneElement,
    config,
    savingRecord,
    onSaveRecord
  ]);
  const isStageLike = sceneElement.elementKind === import_types.FLOOR_MAP_STAGE_ELEMENT_KIND;
  const toggleLayoutLock = () => {
    onUpdate({
      layoutTransformLocked: !sceneElement.layoutTransformLocked
    });
  };
  const panelScrollRef = (0, import_react.useRef)(null);
  const getSelectPopupContainer = (0, import_react.useCallback)((node) => {
    return node.parentElement ?? panelScrollRef.current ?? document.body;
  }, []);
  const dragScrollRef = (0, import_react.useRef)({
    active: false,
    pointerId: -1,
    startY: 0,
    startScrollTop: 0
  });
  const isDragScrollSurface = (0, import_react.useCallback)((target) => {
    if (!(target instanceof Element)) return false;
    return !target.closest(
      'input,textarea,button,select,.ant-select,.ant-select-dropdown,.pisell-lowcode-select-dropdown,.rc-select-dropdown,.ant-input,[contenteditable="true"]'
    );
  }, []);
  const handlePanelPointerDown = (0, import_react.useCallback)(
    (e) => {
      if (!isDragScrollSurface(e.target)) return;
      const el = panelScrollRef.current;
      if (!el || el.scrollHeight <= el.clientHeight) return;
      el.setPointerCapture(e.pointerId);
      dragScrollRef.current = {
        active: true,
        pointerId: e.pointerId,
        startY: e.clientY,
        startScrollTop: el.scrollTop
      };
    },
    [isDragScrollSurface]
  );
  const handlePanelPointerMove = (0, import_react.useCallback)(
    (e) => {
      const d = dragScrollRef.current;
      if (!d.active || e.pointerId !== d.pointerId) return;
      const el = panelScrollRef.current;
      if (!el) return;
      el.scrollTop = d.startScrollTop + (d.startY - e.clientY);
    },
    []
  );
  const endPanelDragScroll = (0, import_react.useCallback)(
    (e) => {
      var _a2;
      const d = dragScrollRef.current;
      if (!d.active || e.pointerId !== d.pointerId) return;
      dragScrollRef.current = {
        active: false,
        pointerId: -1,
        startY: 0,
        startScrollTop: 0
      };
      try {
        (_a2 = panelScrollRef.current) == null ? void 0 : _a2.releasePointerCapture(e.pointerId);
      } catch {
      }
    },
    []
  );
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      ref: panelScrollRef,
      className: (0, import_classnames.default)(`${PREFIX}-edit-panel`, className),
      onPointerDown: handlePanelPointerDown,
      onPointerMove: handlePanelPointerMove,
      onPointerUp: endPanelDragScroll,
      onPointerCancel: endPanelDragScroll
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-header` }, /* @__PURE__ */ import_react.default.createElement("span", { className: `${PREFIX}-edit-panel-header-title` }, ep.elementProps), /* @__PURE__ */ import_react.default.createElement(
      import_antd.Button,
      {
        type: "text",
        size: "large",
        className: `${PREFIX}-edit-panel-close`,
        icon: /* @__PURE__ */ import_react.default.createElement(import_icons.CloseOutlined, null),
        "aria-label": ep.closeAria,
        onClick: onClose
      }
    )),
    (formHasUnappliedChanges || layoutDraftDirty) && /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-hints`, role: "status" }, formHasUnappliedChanges ? /* @__PURE__ */ import_react.default.createElement("p", { className: `${PREFIX}-edit-panel-hint warn` }, ep.hintApply) : null, layoutDraftDirty ? /* @__PURE__ */ import_react.default.createElement("p", { className: `${PREFIX}-edit-panel-hint muted` }, ep.hintSave) : null),
    swappableKinds.length > 1 ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-kind-row` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-record-bind-label` }, ep.labelElementKind), /* @__PURE__ */ import_react.default.createElement(
      import_antd.Select,
      {
        size: "large",
        value: sceneElement.elementKind,
        options: swappableKinds.map((k) => ({
          value: k.value,
          label: k.label
        })),
        onChange: handleElementKindChange,
        getPopupContainer: getSelectPopupContainer,
        style: { width: "100%", marginBottom: 12 }
      }
    )) : null,
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form,
      {
        form,
        layout: "vertical",
        size: "large",
        onFinish: handleFinish,
        initialValues,
        onValuesChange: () => {
          if (skipFormValuesChangeRef.current) return;
          setFormHasUnappliedChanges(true);
        }
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-layout-lock-header` }, /* @__PURE__ */ import_react.default.createElement("span", { className: `${PREFIX}-edit-panel-layout-lock-title` }, ep.sectionLayout), /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          type: "text",
          size: "large",
          className: `${PREFIX}-edit-panel-layout-lock-btn`,
          icon: layoutLocked ? /* @__PURE__ */ import_react.default.createElement(import_icons.LockOutlined, null) : /* @__PURE__ */ import_react.default.createElement(import_icons.UnlockOutlined, null),
          "aria-pressed": layoutLocked,
          onClick: toggleLayoutLock,
          title: layoutLocked ? ep.lockOn : ep.lockOff
        }
      )),
      /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-xy-row` }, /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { name: "x", label: ep.labelX }, /* @__PURE__ */ import_react.default.createElement(import_antd.InputNumber, { style: { width: "100%" }, disabled: layoutLocked })), /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { name: "y", label: ep.labelY }, /* @__PURE__ */ import_react.default.createElement(import_antd.InputNumber, { style: { width: "100%" }, disabled: layoutLocked })), /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { name: "zIndex", label: ep.labelZ }, /* @__PURE__ */ import_react.default.createElement(import_antd.InputNumber, { style: { width: "100%" }, disabled: layoutLocked }))),
      /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-size-row` }, /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { name: "width", label: ep.labelWidth }, /* @__PURE__ */ import_react.default.createElement(
        import_antd.InputNumber,
        {
          style: { width: "100%" },
          min: 20,
          disabled: layoutLocked
        }
      )), /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { name: "height", label: ep.labelHeight }, /* @__PURE__ */ import_react.default.createElement(
        import_antd.InputNumber,
        {
          style: { width: "100%" },
          min: 20,
          disabled: layoutLocked
        }
      ))),
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Form.Item,
        {
          name: "name",
          label: isStageLike ? ep.labelNameStage : ep.labelName
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_antd.Input,
          {
            placeholder: isStageLike ? ep.phNameStage : ep.phName,
            allowClear: true
          }
        )
      ),
      kindAllowsNameAsTitle ? (
        /**
         * 仅在 kindConfig.nameAsTitleConfigurable 时渲染。
         * 业务侧通过 {@link resolveSceneElementDisplayTitle} 读取该偏好，
         * 决定卡片标题是否覆盖业务字段（如 row.main_field / row.code）。
         */
        /* @__PURE__ */ import_react.default.createElement(
          import_antd.Form.Item,
          {
            name: "nameAsTitle",
            valuePropName: "checked",
            extra: ep.tipNameAsTitle,
            style: { marginTop: -4 }
          },
          /* @__PURE__ */ import_react.default.createElement(import_antd.Checkbox, null, ep.labelNameAsTitle)
        )
      ) : null,
      isImageKind ? /* @__PURE__ */ import_react.default.createElement(
        import_antd.Form.Item,
        {
          name: "imageUrl",
          label: ep.labelImageUrl,
          extra: ep.extraImageUrl
        },
        /* @__PURE__ */ import_react.default.createElement(import_antd.Input, { allowClear: true, placeholder: ep.phHttps })
      ) : null,
      isBuiltinShapeKind ? (
        /**
         * 内置图形选择：与图片图元的 imageUrl 字段对位，但把 URL 输入换成 Select；
         * 选项由 {@link FLOOR_MAP_BUILTIN_SHAPES} 驱动（厕所 / 分隔 / 柱子 / 沙发 / 大门 等）。
         * 用 i18n key 取展示名，跟随引擎语言切换。
         */
        /* @__PURE__ */ import_react.default.createElement(
          import_antd.Form.Item,
          {
            name: "builtinShapeKey",
            label: ep.labelBuiltinShape,
            extra: ep.extraBuiltinShape
          },
          /* @__PURE__ */ import_react.default.createElement(
            import_antd.Select,
            {
              allowClear: true,
              placeholder: ep.phBuiltinShape,
              getPopupContainer: getSelectPopupContainer,
              options: import_floorMapBuiltinShapes.FLOOR_MAP_BUILTIN_SHAPES.map((s) => ({
                value: s.key,
                label: import_utils.locales.getText(s.labelKey)
              }))
            }
          )
        )
      ) : null,
      /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { name: "canvasId", label: ep.labelCanvas }, /* @__PURE__ */ import_react.default.createElement(
        import_antd.Select,
        {
          options: canvasOptions.map((c) => ({
            value: c.id,
            label: (0, import_floorMapCanvasDisplay.getFloorMapCanvasDisplayName)(c, engineLocale)
          })),
          allowClear: false,
          getPopupContainer: getSelectPopupContainer
        }
      )),
      /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, null, /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { type: "primary", htmlType: "submit", size: "large" }, ep.apply))
    ),
    showDataBindingSection && /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-record` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-record-title` }, ep.dataBinding), /* @__PURE__ */ import_react.default.createElement("p", { className: `${PREFIX}-edit-panel-record-draft-note` }, ep.dataBindingNote), allowedKeys.length >= 1 ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-record-bind` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-record-bind-label` }, ep.labelDataSource), /* @__PURE__ */ import_react.default.createElement(
      import_antd.Select,
      {
        size: "large",
        style: { width: "100%" },
        placeholder: ep.phDataSource,
        value: binding == null ? void 0 : binding.dataSourceKey,
        options: allowedKeys.map((k) => ({
          value: k,
          label: dataSourceLabels[k] ?? k
        })),
        onChange: (key) => {
          if (!key && bindingPolicy === "optional") {
            onUpdate({ dataBinding: void 0 });
            return;
          }
          if (!key) return;
          onUpdate({
            dataBinding: {
              dataSourceKey: key,
              recordId: (binding == null ? void 0 : binding.dataSourceKey) === key ? binding.recordId : ""
            }
          });
        },
        allowClear: bindingPolicy === "optional",
        getPopupContainer: getSelectPopupContainer
      }
    )) : null, allowedKeys.length >= 1 && /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-record-bind` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-record-bind-label` }, ep.labelPickRow), /* @__PURE__ */ import_react.default.createElement(
      import_antd.Select,
      {
        size: "large",
        placeholder: dataRecordBindOptions.length ? ep.phPickRow : ep.phNoRows,
        style: { width: "100%" },
        value: hasBoundDataRecord ? binding == null ? void 0 : binding.recordId : void 0,
        allowClear: bindingPolicy === "optional",
        options: dataRecordBindOptions,
        getPopupContainer: getSelectPopupContainer,
        onChange: (newId) => {
          const key = (binding == null ? void 0 : binding.dataSourceKey) ?? allowedKeys[0];
          if (!key) return;
          if (!newId) {
            onUpdate({ dataBinding: void 0 });
            return;
          }
          const row = (dataSources[key] ?? []).find(
            (r) => r.id === newId
          );
          onUpdate({
            dataBinding: {
              dataSourceKey: key,
              recordId: newId
            },
            name: row ? String(
              (() => {
                var _a2;
                const m = row.main_field;
                if (m != null && String(m).trim() !== "") {
                  return ((_a2 = String(m).split(" ## ")[0]) == null ? void 0 : _a2.trim()) ?? newId;
                }
                return row.name ?? row.code ?? newId;
              })()
            ) : void 0
          });
        }
      }
    ), !hasBoundDataRecord && /* @__PURE__ */ import_react.default.createElement("p", { className: `${PREFIX}-edit-panel-record-bind-hint` }, ep.hintUnbound))),
    showDataRecordEditorSection && binding && /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-record` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-record-title` }, ep.recordTitle), hasCustomRecordForm && recordFormContext && recordFormSlotRaw != null ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-record-custom` }, resolveDataSourceRecordForm(
      recordFormSlotRaw,
      recordFormContext
    )) : null, !hasCustomRecordForm && onSaveRecord ? /* @__PURE__ */ import_react.default.createElement(
      import_FloorMapDataForm.FloorMapDataForm,
      {
        dataSourceKey: binding.dataSourceKey,
        recordId: binding.recordId,
        record,
        dataSources,
        onSave: onSaveRecord,
        saving: savingRecord,
        columns: recordFormColumns == null ? void 0 : recordFormColumns[binding.dataSourceKey]
      }
    ) : null),
    config.canvasUi.canEdit && onDelete ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-panel-footer` }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Popconfirm,
      {
        title: ep.popTitle,
        description: ep.popDesc,
        onConfirm: onDelete,
        okText: ep.btnOkDelete,
        cancelText: ep.btnCancel,
        okButtonProps: { danger: true },
        zIndex: import_floorMapLayoutConstants.FLOOR_MAP_CONFIRM_OVERLAY_Z_INDEX
      },
      /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { type: "default", danger: true, block: true, size: "large" }, ep.btnDelete)
    )) : null
  );
}
var FloorMapEditPanel_default = FloorMapEditPanel;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FloorMapEditPanel
});
