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