import { floorMapSavedConfigToRemotePatch } from "../shopFloorPlan/shopFloorPlanPure.js";
//#region src/components/pisellFloorMapLayout/utils/floorMapRemotePersist.ts
/**
* 将 `floorMap.onSave` 包装为：先持久化到远端，再 `setRemoteFloorPlanView(floorMapSavedConfigToRemotePatch)` 与用户 `prevOnSave`。
*/
function wrapFloorMapOnSaveWithRemotePersist(params) {
	const { canPersist, persistTargetId, persist, setRemoteFloorPlanView, onFloorPlanPersisted, prevOnSave, onPersistError } = params;
	if (!canPersist) return (config) => {
		prevOnSave === null || prevOnSave === void 0 || prevOnSave(config);
	};
	return (config) => {
		persist(persistTargetId, config).then(() => {
			setRemoteFloorPlanView(floorMapSavedConfigToRemotePatch(config));
			onFloorPlanPersisted === null || onFloorPlanPersisted === void 0 || onFloorPlanPersisted();
			prevOnSave === null || prevOnSave === void 0 || prevOnSave(config);
		}).catch((err) => {
			onPersistError === null || onPersistError === void 0 || onPersistError(err);
		});
	};
}
//#endregion
export { wrapFloorMapOnSaveWithRemotePersist };
