require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_index = require("../../../utils/index.js");
const require_reservationMock = require("./reservationMock.js");
const require_create_floor_map = require("../api/create-floor-map.js");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
//#region src/plus/pisellReservation/floorMap/floorPlanApi.ts
/**
* 店铺平面图：在 {@link createShopFloorPlanClient}（materials）之上绑定引擎 `request`，
* 并保留预约专用的默认 POST 体、Toast 与 {@link shopLayoutToSceneElements} 图元种类默认值。
*/
const I18N_FLOOR_PLAN_SAVE_FAILED = "pisell-reservation.floor-plan.save-failed";
const PISELL_RESERVATION_FLOOR_PLAN_CODE = "pisell_reservation";
const shopClient = (0, _pisell_materials.createShopFloorPlanClient)({
	http: {
		get: (url, params, config) => require_index.request.getRequest().get(url, params !== null && params !== void 0 ? params : {}, config !== null && config !== void 0 ? config : {}),
		post: (url, body, config) => require_index.request.getRequest().post(url, body !== null && body !== void 0 ? body : {}, config !== null && config !== void 0 ? config : {}),
		put: (url, body, config) => require_index.request.getRequest().put(url, body !== null && body !== void 0 ? body : {}, config !== null && config !== void 0 ? config : {})
	},
	saveFailedMessage: _pisell_utils.locales.getText(I18N_FLOOR_PLAN_SAVE_FAILED)
});
shopClient.getShopFloorPlanByCode.bind(shopClient);
shopClient.postShopFloorPlan.bind(shopClient);
const putShopFloorPlan = shopClient.putShopFloorPlan.bind(shopClient);
const unsubscribeShopFloorPlanCodeQuery = shopClient.unsubscribeShopFloorPlanCodeQuery.bind(shopClient);
/**
* 404 时 POST 创建使用预约默认 JSON（`api/create-floor-map.json`）。
*/
function ensureShopFloorPlanByCode(_x, _x2) {
	return _ensureShopFloorPlanByCode.apply(this, arguments);
}
function _ensureShopFloorPlanByCode() {
	_ensureShopFloorPlanByCode = require_asyncToGenerator._asyncToGenerator(function* (code, subscribe) {
		return shopClient.ensureShopFloorPlanByCode(code, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, subscribe), {}, { buildDefaultPostBody: buildDefaultReservationFloorPlanPostBody }));
	});
	return _ensureShopFloorPlanByCode.apply(this, arguments);
}
function buildDefaultReservationFloorPlanPostBody(code) {
	const trimmed = code === null || code === void 0 ? void 0 : code.trim();
	if (!trimmed) throw new Error("floor plan code is required");
	const j = require_create_floor_map.default;
	return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({
		code: trimmed,
		name: require_objectSpread2._objectSpread2({}, 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 } : {});
}
/**
* 将扁平 layout 转为 sceneElements；圆/方桌 elementKind 使用预约默认。
*/
function shopLayoutToSceneElements(layout, options) {
	return (0, _pisell_materials.shopLayoutToSceneElements)(layout, {
		canvasId: options.canvasId,
		dataSourceKey: options.dataSourceKey,
		rectElementKind: require_reservationMock.RESERVATION_BOUND_TABLE_ELEMENT_KIND,
		circleElementKind: require_reservationMock.RESERVATION_BOUND_ROUND_TABLE_ELEMENT_KIND
	});
}
function saveViewConfigToShopFloorPlan(_x3, _x4, _x5) {
	return _saveViewConfigToShopFloorPlan.apply(this, arguments);
}
function _saveViewConfigToShopFloorPlan() {
	_saveViewConfigToShopFloorPlan = require_asyncToGenerator._asyncToGenerator(function* (id, config, options) {
		var _options$putFloorPlan;
		const body = (0, _pisell_materials.buildFloorPlanPutBody)(config, options);
		return ((_options$putFloorPlan = options.putFloorPlan) !== null && _options$putFloorPlan !== void 0 ? _options$putFloorPlan : putShopFloorPlan)(id, body);
	});
	return _saveViewConfigToShopFloorPlan.apply(this, arguments);
}
function toastFloorPlanSaveError(err) {
	(0, _pisell_materials.PisellToast)({ content: err instanceof Error ? err.message : String(err) });
}
function toastFloorPlanLoadError(err) {
	(0, _pisell_materials.PisellToast)({ content: err instanceof Error ? err.message : String(err) });
}
//#endregion
exports.PISELL_RESERVATION_FLOOR_PLAN_CODE = PISELL_RESERVATION_FLOOR_PLAN_CODE;
exports.ensureShopFloorPlanByCode = ensureShopFloorPlanByCode;
exports.saveViewConfigToShopFloorPlan = saveViewConfigToShopFloorPlan;
exports.shopLayoutToSceneElements = shopLayoutToSceneElements;
exports.toastFloorPlanLoadError = toastFloorPlanLoadError;
exports.toastFloorPlanSaveError = toastFloorPlanSaveError;
exports.unsubscribeShopFloorPlanCodeQuery = unsubscribeShopFloorPlanCodeQuery;
