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/floorMap/floorPlanApi.ts
var floorPlanApi_exports = {};
__export(floorPlanApi_exports, {
  FLOOR_PLAN_DUPLICATE_CODE: () => FLOOR_PLAN_DUPLICATE_CODE,
  PISELL_RESERVATION_FLOOR_PLAN_CODE: () => PISELL_RESERVATION_FLOOR_PLAN_CODE,
  RESERVATION_DEFAULT_FLOOR_PLAN_ID: () => RESERVATION_DEFAULT_FLOOR_PLAN_ID,
  buildDefaultReservationFloorPlanPostBody: () => buildDefaultReservationFloorPlanPostBody,
  buildFloorPlanPutBody: () => import_materials3.buildFloorPlanPutBody,
  ensureShopFloorPlanByCode: () => ensureShopFloorPlanByCode,
  floorMapSavedConfigToRemotePatch: () => import_materials3.floorMapSavedConfigToRemotePatch,
  getShopFloorPlanByCode: () => getShopFloorPlanByCode,
  inferCanvasSizeFromScene: () => import_materials3.inferCanvasSizeFromScene,
  isFloorPlanDuplicateCodeError: () => isFloorPlanDuplicateCodeError,
  isHttpNotFoundError: () => import_materials3.isHttpNotFoundError,
  isShopFloorPlanNotFoundResponse: () => import_materials3.isShopFloorPlanNotFoundResponse,
  mergeFloorPlanViewRemote: () => import_materials3.mergeFloorPlanViewRemote,
  parseLayoutFieldToViewConfigPatch: () => import_materials3.parseLayoutFieldToViewConfigPatch,
  pickFloorPlanDetail: () => import_materials3.pickFloorPlanDetail,
  postShopFloorPlan: () => postShopFloorPlan,
  putShopFloorPlan: () => putShopFloorPlan,
  saveViewConfigToShopFloorPlan: () => saveViewConfigToShopFloorPlan,
  sceneElementsToShopLayout: () => import_materials3.sceneElementsToShopLayout,
  shopLayoutToSceneElements: () => shopLayoutToSceneElements,
  toastFloorPlanLoadError: () => toastFloorPlanLoadError,
  toastFloorPlanSaveError: () => toastFloorPlanSaveError,
  unsubscribeShopFloorPlanCodeQuery: () => unsubscribeShopFloorPlanCodeQuery,
  viewConfigToLayoutPayload: () => import_materials3.viewConfigToLayoutPayload
});
module.exports = __toCommonJS(floorPlanApi_exports);
var import_materials = require("@pisell/materials");
var import_materials2 = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_utils2 = require("../../../utils");
var import_reservationMock = require("./reservationMock");
var import_create_floor_map = __toESM(require("../api/create-floor-map.json"));
var import_materials3 = require("@pisell/materials");
var I18N_FLOOR_PLAN_SAVE_FAILED = "pisell-reservation.floor-plan.save-failed";
var FLOOR_PLAN_DUPLICATE_CODE = "floorPlanDuplicateCode";
var PISELL_RESERVATION_FLOOR_PLAN_CODE = "pisell_reservation";
var RESERVATION_DEFAULT_FLOOR_PLAN_ID = 1;
function isFloorPlanDuplicateCodeError(err) {
  return (0, import_materials2.isFloorPlanDuplicateCodeError)(err);
}
var shopFloorPlanHttp = {
  get: (url, params, config) => import_utils2.request.getRequest().get(url, params ?? {}, config ?? {}),
  post: (url, body, config) => import_utils2.request.getRequest().post(url, body ?? {}, config ?? {}),
  put: (url, body, config) => import_utils2.request.getRequest().put(url, body ?? {}, config ?? {})
};
var shopClient = (0, import_materials2.createShopFloorPlanClient)({
  http: shopFloorPlanHttp,
  saveFailedMessage: import_utils.locales.getText(I18N_FLOOR_PLAN_SAVE_FAILED)
});
var getShopFloorPlanByCode = shopClient.getShopFloorPlanByCode.bind(
  shopClient
);
var postShopFloorPlan = shopClient.postShopFloorPlan.bind(shopClient);
var putShopFloorPlan = shopClient.putShopFloorPlan.bind(shopClient);
var unsubscribeShopFloorPlanCodeQuery = shopClient.unsubscribeShopFloorPlanCodeQuery.bind(shopClient);
async function ensureShopFloorPlanByCode(code, subscribe) {
  return shopClient.ensureShopFloorPlanByCode(code, {
    ...subscribe,
    buildDefaultPostBody: buildDefaultReservationFloorPlanPostBody
  });
}
function buildDefaultReservationFloorPlanPostBody(code) {
  const trimmed = code == null ? void 0 : code.trim();
  if (!trimmed) {
    throw new Error("floor plan code is required");
  }
  const j = import_create_floor_map.default;
  return {
    code: trimmed,
    name: { ...j.name },
    layout: JSON.parse(JSON.stringify(j.layout)),
    canvas_width: j.canvas_width,
    canvas_height: j.canvas_height,
    ...j.sort !== void 0 ? { sort: j.sort } : {},
    ...j.status !== void 0 ? { status: j.status } : {}
  };
}
function shopLayoutToSceneElements(layout, options) {
  return (0, import_materials2.shopLayoutToSceneElements)(layout, {
    canvasId: options.canvasId,
    dataSourceKey: options.dataSourceKey,
    rectElementKind: import_reservationMock.RESERVATION_BOUND_TABLE_ELEMENT_KIND,
    circleElementKind: import_reservationMock.RESERVATION_BOUND_ROUND_TABLE_ELEMENT_KIND
  });
}
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) {
  const msg = err instanceof Error ? err.message : String(err);
  (0, import_materials.PisellToast)({ content: msg });
}
function toastFloorPlanLoadError(err) {
  const msg = err instanceof Error ? err.message : String(err);
  (0, import_materials.PisellToast)({ content: msg });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FLOOR_PLAN_DUPLICATE_CODE,
  PISELL_RESERVATION_FLOOR_PLAN_CODE,
  RESERVATION_DEFAULT_FLOOR_PLAN_ID,
  buildDefaultReservationFloorPlanPostBody,
  buildFloorPlanPutBody,
  ensureShopFloorPlanByCode,
  floorMapSavedConfigToRemotePatch,
  getShopFloorPlanByCode,
  inferCanvasSizeFromScene,
  isFloorPlanDuplicateCodeError,
  isHttpNotFoundError,
  isShopFloorPlanNotFoundResponse,
  mergeFloorPlanViewRemote,
  parseLayoutFieldToViewConfigPatch,
  pickFloorPlanDetail,
  postShopFloorPlan,
  putShopFloorPlan,
  saveViewConfigToShopFloorPlan,
  sceneElementsToShopLayout,
  shopLayoutToSceneElements,
  toastFloorPlanLoadError,
  toastFloorPlanSaveError,
  unsubscribeShopFloorPlanCodeQuery,
  viewConfigToLayoutPayload
});
