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_objectWithoutProperties = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_index = require("../../../utils/index.js");
const require_create_topology_floor_map = require("../api/create-topology-floor-map.js");
const require_topologyMock = require("../topologyMock.js");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
//#region src/plus/pisellTopology/floorPlan/topologyFloorPlanApi.ts
/**
* 拓扑页 shop floor-plan API（绑定引擎 request）
*/
const _excluded = ["buildDefaultPostBody"];
const client = (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("pisell-topology.floor-plan.save-failed") || "Failed to save topology floor plan"
});
client.getShopFloorPlanByCode.bind(client);
const putShopFloorPlan = client.putShopFloorPlan.bind(client);
const unsubscribeShopFloorPlanCodeQuery = client.unsubscribeShopFloorPlanCodeQuery.bind(client);
function buildDefaultTopologyFloorPlanPostBody(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_topology_floor_map.default;
	return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({
		code: trimmed,
		name: require_objectSpread2._objectSpread2({}, j.name),
		layout: (0, _pisell_materials.viewConfigToLayoutPayload)(require_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 } : {});
}
function ensureShopFloorPlanByCode(_x, _x2) {
	return _ensureShopFloorPlanByCode.apply(this, arguments);
}
function _ensureShopFloorPlanByCode() {
	_ensureShopFloorPlanByCode = require_asyncToGenerator._asyncToGenerator(function* (code, subscribe) {
		const _ref = subscribe !== null && subscribe !== void 0 ? subscribe : {}, { buildDefaultPostBody } = _ref, rest = require_objectWithoutProperties._objectWithoutProperties(_ref, _excluded);
		return client.ensureShopFloorPlanByCode(code, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, rest), {}, { buildDefaultPostBody: buildDefaultPostBody !== null && buildDefaultPostBody !== void 0 ? buildDefaultPostBody : buildDefaultTopologyFloorPlanPostBody }));
	});
	return _ensureShopFloorPlanByCode.apply(this, arguments);
}
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.ensureShopFloorPlanByCode = ensureShopFloorPlanByCode;
exports.saveViewConfigToShopFloorPlan = saveViewConfigToShopFloorPlan;
exports.toastFloorPlanLoadError = toastFloorPlanLoadError;
exports.toastFloorPlanSaveError = toastFloorPlanSaveError;
exports.unsubscribeShopFloorPlanCodeQuery = unsubscribeShopFloorPlanCodeQuery;
