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/pisellTopology/floorPlan/topologyFloorPlanApi.ts
var topologyFloorPlanApi_exports = {};
__export(topologyFloorPlanApi_exports, {
  buildDefaultTopologyFloorPlanPostBody: () => buildDefaultTopologyFloorPlanPostBody,
  buildFloorPlanPutBody: () => import_materials3.buildFloorPlanPutBody,
  ensureShopFloorPlanByCode: () => ensureShopFloorPlanByCode,
  floorMapSavedConfigToRemotePatch: () => import_materials3.floorMapSavedConfigToRemotePatch,
  getShopFloorPlanByCode: () => getShopFloorPlanByCode,
  isFloorPlanDuplicateCodeError: () => isFloorPlanDuplicateCodeError,
  mergeFloorPlanViewRemote: () => import_materials3.mergeFloorPlanViewRemote,
  parseLayoutFieldToViewConfigPatch: () => import_materials3.parseLayoutFieldToViewConfigPatch,
  putShopFloorPlan: () => putShopFloorPlan,
  saveViewConfigToShopFloorPlan: () => saveViewConfigToShopFloorPlan,
  toastFloorPlanLoadError: () => toastFloorPlanLoadError,
  toastFloorPlanSaveError: () => toastFloorPlanSaveError,
  unsubscribeShopFloorPlanCodeQuery: () => unsubscribeShopFloorPlanCodeQuery
});
module.exports = __toCommonJS(topologyFloorPlanApi_exports);
var import_materials = require("@pisell/materials");
var import_materials2 = require("@pisell/materials");
var import_utils = require("../../../utils");
var import_topologyLocale = require("../topologyLocale");
var import_create_topology_floor_map = __toESM(require("../api/create-topology-floor-map.json"));
var import_topologyMock = require("../topologyMock");
var import_materials3 = require("@pisell/materials");
var I18N_SAVE_FAILED = "pisell-topology.floor-plan.save-failed";
function isFloorPlanDuplicateCodeError(err) {
  return (0, import_materials2.isFloorPlanDuplicateCodeError)(err);
}
var http = {
  get: (url, params, config) => import_utils.request.getRequest().get(url, params ?? {}, config ?? {}),
  post: (url, body, config) => import_utils.request.getRequest().post(url, body ?? {}, config ?? {}),
  put: (url, body, config) => import_utils.request.getRequest().put(url, body ?? {}, config ?? {})
};
var client = (0, import_materials2.createShopFloorPlanClient)({
  http,
  useShopApi: true,
  /**
   * 保存失败兜底：按当前 umi_locale 解析（模块加载时固化会无法随语言切换）。
   */
  getSaveFailedMessage: () => (0, import_topologyLocale.getTopologyText)(I18N_SAVE_FAILED, (0, import_topologyLocale.resolveTopologyDisplayLocale)(void 0)) || "Failed to save topology floor plan"
});
var getShopFloorPlanByCode = client.getShopFloorPlanByCode.bind(client);
var putShopFloorPlan = client.putShopFloorPlan.bind(client);
var unsubscribeShopFloorPlanCodeQuery = client.unsubscribeShopFloorPlanCodeQuery.bind(client);
function buildDefaultTopologyFloorPlanPostBody(code) {
  const trimmed = code == null ? void 0 : code.trim();
  if (!trimmed) throw new Error("floor plan code is required");
  const j = import_create_topology_floor_map.default;
  return {
    code: trimmed,
    name: { ...j.name },
    layout: (0, import_materials.viewConfigToLayoutPayload)((0, import_topologyMock.getTopologyFloorMapShellConfig)()),
    canvas_width: j.canvas_width,
    canvas_height: j.canvas_height,
    ...j.sort !== void 0 ? { sort: j.sort } : {},
    ...j.status !== void 0 ? { status: j.status } : {}
  };
}
async function ensureShopFloorPlanByCode(code, subscribe) {
  const { buildDefaultPostBody, ...rest } = subscribe ?? {};
  return client.ensureShopFloorPlanByCode(code, {
    ...rest,
    buildDefaultPostBody: buildDefaultPostBody ?? buildDefaultTopologyFloorPlanPostBody
  });
}
async function saveViewConfigToShopFloorPlan(id, config, options) {
  const body = (0, import_materials2.buildFloorPlanPutBody)(config, options);
  const put = options.putFloorPlan ?? putShopFloorPlan;
  return put(id, body);
}
function toastFloorPlanSaveError(err) {
  (0, import_materials.PisellToast)({
    content: err instanceof Error ? err.message : String(err)
  });
}
function toastFloorPlanLoadError(err) {
  (0, import_materials.PisellToast)({
    content: err instanceof Error ? err.message : String(err)
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildDefaultTopologyFloorPlanPostBody,
  buildFloorPlanPutBody,
  ensureShopFloorPlanByCode,
  floorMapSavedConfigToRemotePatch,
  getShopFloorPlanByCode,
  isFloorPlanDuplicateCodeError,
  mergeFloorPlanViewRemote,
  parseLayoutFieldToViewConfigPatch,
  putShopFloorPlan,
  saveViewConfigToShopFloorPlan,
  toastFloorPlanLoadError,
  toastFloorPlanSaveError,
  unsubscribeShopFloorPlanCodeQuery
});
